poj 3624 Charm Bracelet(简单01背包)

举报
xindoo 发表于 2022/04/16 02:12:29 2022/04/16
【摘要】 题目链接 Description 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...

题目链接

Description

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 weightWi (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.

简单01背包,无需多言。


  
  1. //poj 3624
  2. //2013-04-12-16.51
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <algorithm>
  6. using namespace std;
  7. int dp[12900];
  8. int w[3410];
  9. int d[3410];
  10. int main()
  11. {
  12. int n, m;
  13. while (scanf("%d %d",&n, &m) != EOF)
  14. {
  15. for (int i = 1; i <= n; i++)
  16. scanf("%d %d",&w[i], &d[i]);
  17. memset(dp, 0, sizeof(dp));
  18. for (int i = 1; i <= n; i++)
  19. {
  20. for (int j = m; j >= w[i]; j--)
  21. dp[j] = max(dp[j],dp[j-w[i]] + d[i]);
  22. }
  23. printf("%d\n",dp[m]);
  24. }
  25. return 0;
  26. }


文章来源: xindoo.blog.csdn.net,作者:xindoo,版权归原作者所有,如需转载,请联系作者。

原文链接:xindoo.blog.csdn.net/article/details/8794253

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。