| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 853 人关注过本帖
标题:大虾高手都来看看帮一下忙!求解一道HOJ题目。。。
只看楼主 加入收藏
fightingsss
Rank: 6Rank: 6
等 级:侠之大者
帖 子:97
专家分:471
注 册:2010-11-12
结帖率:80%
收藏
已结贴  问题点数:20 回复次数:4 
大虾高手都来看看帮一下忙!求解一道HOJ题目。。。
Recently, a shopping mall is making sale promotional activity. If you buy goods worth m yuan or more, they will return you r yuan cash. bailey is so poor that he wants to get r yuan with minimum cost. Please help him.


Input

The first line is an integer c which shows the number of cases. Each case contains 2 lines. The first line has 2 positive integers n and m, n is the number of goods. The second line contains n positive integers which are the price of each goods. You must remember that bailey hates to buy two same goods.(0<n<100, 0<m<1000)


Output

For each case print the minimum cost in a single line.


Sample Input


 2 2 100 50 70 3 100 50 50 70

Sample Output


 120 100
搜索更多相关主题的帖子: Recently return 
2011-05-12 19:49
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
收藏
得分:7 
搞个input 和 output 范例 也不排列好
2011-05-12 23:41
lucky563591
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:765
专家分:2103
注 册:2009-11-18
收藏
得分:7 
你是没有认真看题吧?
2011-05-13 07:56
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
收藏
得分:0 

Sample Input
2
2 100
50 70
3 100
50 50 70

Sample Output
120
100
2011-05-13 08:07
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:7 
程序代码:
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

#define MSG
const int NUM = 80;

vector<unsigned int>  Goods;
bitset<NUM> bitSet;
unsigned int m, n, x;

void getInitMsg(void);
void recursion(unsigned int index, unsigned int uppound);
void deal();

int wmain(void)
{
    deal();
    return 0;
}

void getInitMsg(void)
{
#ifdef MSG
    cout << "输入商品数量: ";
#endif
    cin >> n;
#ifdef MSG
    cout << "输入优惠最低消费金额: " ;
#endif
    cin >> m;
#ifdef MSG
    cout << "输入商品的价格:";
#endif
    for (unsigned int sum=0,i=0; i<n; ++i)
    {
        cin >> x;
        sum += x;
        Goods.push_back(x);
        x = sum;
    }
}

void recursion(unsigned int index, unsigned int uppound)
{
    if (index >= uppound && uppound < n)
    {
        for (unsigned int sum=0, i=0; i<Goods.size(); ++i)
        {
            if (bitSet.test(i))
            {
                sum += Goods[i];
            }
        }
        if (sum >= m && sum <= x)
        {
            x = sum;
        }
        return;
    }
    else
    {
        bitSet.set(index);
        recursion(index+1, uppound);
        bitSet.reset(index);
        recursion(index+1, uppound);
    }
}

void deal()
{
    unsigned int i;

    getInitMsg();
    for (i=0; i<Goods.size(); ++i)
    {
        recursion(0, i);
    }

    if (x < m)
    {
        cout << "消费金额不足优惠条件" << endl;
    }
    else
    {
        cout << "最小的消费为: " << x << endl;
    }
}
2011-05-15 15:19
快速回复:大虾高手都来看看帮一下忙!求解一道HOJ题目。。。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017483 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved