博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3624 Charm Bracelet
阅读量:4315 次
发布时间:2019-06-06

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

Charm Bracelet

Time Limit: 1000ms
Memory Limit: 65536KB
This problem will be judged on 
PKU. Original ID: 
64-bit integer IO format: %lld      Java class name: Main

Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤N ≤ 3,402) available charms. Each charm i in the supplied list has a weight Wi (1 ≤ Wi ≤ 400), a 'desirability' factor Di (1 ≤ Di ≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more than M (1 ≤ M ≤ 12,880).

Given that weight limit as a constraint and a list of the charms with their weights and desirability rating, deduce the maximum possible sum of ratings.

 

Input

* Line 1: Two space-separated integers: N and M* Lines 2..N+1: Line i+1 describes charm i with two space-separated integers: Wi and Di

 

Output

* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints

 

Sample Input

4 61 42 63 122 7

Sample Output

23

Source

 
解题:01背包
 
1 #include 
2 #include
3 #include
4 using namespace std; 5 int dp[12900],w[3500],d[3500],n,m; 6 int main(){ 7 while(~scanf("%d %d",&n,&m)){ 8 for(int i = 0; i < n; ++i) 9 scanf("%d %d",w+i,d+i);10 memset(dp,0,sizeof dp);11 for(int i = 0; i < n; ++i)12 for(int j = m; j >= w[i]; --j)13 dp[j] = max(dp[j],dp[j-w[i]] + d[i]);14 printf("%d\n",dp[m]);15 }16 return 0;17 }
View Code

 

转载于:https://www.cnblogs.com/crackpotisback/p/4415715.html

你可能感兴趣的文章
cookie
查看>>
二级图片导航菜单
查看>>
<Using parquet with impala>
查看>>
OpenGL渲染流程
查看>>
委托异步回调
查看>>
扩展欧几里得算法
查看>>
いつでもどこでも本格的に麻雀&チュートリアルが充実!iPhone/iPod touch/iPad向け「雀龍門Mobile」をiPadで遊んでみました...
查看>>
如何重置mysql中的root密码
查看>>
bzoj 3171: [Tjoi2013]循环格 最小费用最大流
查看>>
关于IO的一些数字
查看>>
高放的c++学习笔记之模板与泛型编程
查看>>
bzoj 1089: [SCOI2003]严格n元树
查看>>
mybatis 日期比较
查看>>
更新jdk
查看>>
string与StringBuilder之性能比较
查看>>
python3----练习题(购物车)
查看>>
IOS不错的学习资源特别是图片效果的处理上
查看>>
HDU 2072(字符串的流式操作,学习了)
查看>>
win10 vs2015源码编译opencv、opencv_contrib、Tesseract
查看>>
css取消a标签在移动端点击时的背景颜色
查看>>