设为首页 加入收藏

TOP

hdu2660 Accepted Necklace (DFS)
2014-11-23 21:46:41 来源: 作者: 【 】 浏览:21
Tags:hdu2660 Accepted Necklace DFS

Problem Description
I have N precious stones, and plan to use K of them to make a necklace for my mother, but she won't accept a necklace which is too heavy. Given the value and the weight of each precious stone, please help me find out the most valuable necklace my mother will accept.

Input
The first line of input is the number of cases.
For each case, the first line contains two integers N (N <= 20), the total number of stones, and K (K <= N), the exact number of stones to make a necklace.
Then N lines follow, each containing two integers: a (a<=1000), representing the value of each precious stone, and b (b<=1000), its weight.
The last line of each case contains an integer W, the maximum weight my mother will accept, W <= 1000.

Output
For each case, output the highest possible value of the necklace.


Sample Input
1
2 1
1 1
1 1
3

Sample Output
1
题目意思:求出K个宝石最大价值总和,但重量不能超过W;


#include   struct ston  {      int sa,sw;  };  struct ston s[25],tem;  int su,N,K,W;  void DFS(int i,int suma, int w,int k)  {      int j;      if(su0)          {              su=s[i].sa;              DFS(i,s[i].sa,s[i].sw,1);              if(su>sum)              sum=su;          }          printf("%d\n",sum);      }  }  #include
struct ston
{
    int sa,sw;
};
struct ston s[25],tem;
int su,N,K,W;
void DFS(int i,int suma, int w,int k)
{
    int j;
    if(su0)
        {
            su=s[i].sa;
            DFS(i,s[i].sa,s[i].sw,1);
            if(su>sum)
            sum=su;
        }
        printf("%d\n",sum);
    }
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇大数,高精度计算---大数减法 下一篇UVa 993: Product of digits

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·一篇说人话的文章, (2025-12-27 07:50:09)
·Python Web框架哪家 (2025-12-27 07:50:06)
·基于Python的数据分 (2025-12-27 07:50:03)
·深入理解 Java 集合 (2025-12-27 07:22:48)
·Java集合框架全面解 (2025-12-27 07:22:45)