博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu2660 Accepted Necklace (DFS)
阅读量:4694 次
发布时间:2019-06-09

本文共 1264 字,大约阅读时间需要 4 分钟。

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(su
0) { su=s[i].sa; DFS(i,s[i].sa,s[i].sw,1); if(su>sum) sum=su; } printf("%d\n",sum); }}

转载于:https://www.cnblogs.com/dyllove98/p/3228670.html

你可能感兴趣的文章
20190404 Oracle忘记登陆密码
查看>>
理解c++11正则表达式 (1)
查看>>
Leetcode 3. Longest Substring Without Repeating Characters
查看>>
Spring Boot 错误处理
查看>>
Spark 1.4.1中Beeline使用的gc overhead limit exceeded
查看>>
zookeeper和dubbo的关系
查看>>
Android中调用webservice
查看>>
编译安装zabbix3.4及实现邮件报警
查看>>
《程序是怎样跑起来的》第七章
查看>>
control遍历
查看>>
js实现弹幕效果
查看>>
Java 中Model 与 实体的区别
查看>>
LintCode 55---比较字符串
查看>>
lodash (js实用工具库)
查看>>
并行进程问题
查看>>
微信机器人 简化版
查看>>
360微博提醒增强版的下载地址
查看>>
nginx 报错 HTTP ERROR 500 (PHP数组简写模式)
查看>>
ubuntu命令安装java 6 jdk
查看>>
系统分析与设计第一次作业
查看>>