Charm Bracelet
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 34013   Accepted: 15087

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 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 6
1 4
2 6
3 12
2 7

Sample Output

23

基础01背包飘过

源代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<ctime>
using namespace std; int W[3407];
int D[3407];
int dp[12885];//背包 int main()
{
int N,M;
int i,j;
memset(W,0,sizeof(W));
memset(D,0,sizeof(D));
memset(dp,0,sizeof(dp));
scanf("%d%d",&N,&M);
for(i = 0; i < N; i++)
{
scanf("%d%d",&W[i],&D[i]);
}
for(i = 0; i < N; i++)
{
for(j = M; j >= W[i]; j--)
{
dp[j] = max(dp[j], dp[j - W[i]] + D[i]);
}
}
printf("%d\n",dp[M]);
return 0;
}

POJ3624--01背包的更多相关文章

  1. POJ3624 0-1背包(dp+滚动数组)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 47440   Accepted: 20178 ...

  2. POJ3624(01背包:滚动 实现)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30417   Accepted: 13576 ...

  3. 01背包模板、全然背包 and 多重背包(模板)

    转载请注明出处:http://blog.csdn.net/u012860063 贴一个自觉得解说不错的链接:http://www.cppblog.com/tanky-woo/archive/2010/ ...

  4. UVALive 4870 Roller Coaster --01背包

    题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F ,     D -= K 问在D小于等于一定限度的时 ...

  5. POJ1112 Team Them Up![二分图染色 补图 01背包]

    Team Them Up! Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7608   Accepted: 2041   S ...

  6. Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)

    传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...

  7. 51nod1085(01背包)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085 题意: 中文题诶~ 思路: 01背包模板题. 用dp[ ...

  8. *HDU3339 最短路+01背包

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. codeforces 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses ——(01背包变形)

    题意:给你若干个集合,每个集合内的物品要么选任意一个,要么所有都选,求最后在背包能容纳的范围下最大的价值. 分析:对于每个并查集,从上到下滚动维护即可,其实就是一个01背包= =. 代码如下: #in ...

  10. POJ 3624 Charm Bracelet(01背包)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34532   Accepted: 15301 ...

随机推荐

  1. LeetCode 572. Subtree of Another Tree (是否是另一个树的子树)

    Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and no ...

  2. Appium python自动化测试系列之页面滑动原理讲解(十)

    10.1.1 页面滑动原理分析 在页面滑动查找章节我们就讲了滑动的知识点,只是不知道大家是否有认真练习以及去理解,如果你认真练习.理解了那么我相信这一章节的东西不用看也能够完成,下面我们还是简单分析一 ...

  3. swift 上的 lazy

    lazy顾名思义就是慢吞吞的,万非得一就不动. 那么一个变量也是如此,只有你第一次使用的时候才进去加载.所有又称为延迟加载,需要的时候才加载. ========= 这样做的好处: 1. 模块化,把对象 ...

  4. JSON.stringify实战用法

    1.首先定义一个数组 var teamPlanMinList = new Array(); 2. 定义一个json对象 var json = { "plname":plname, ...

  5. sudo使用详细讲解

    1.原因:让普通用户具有root用户的权限通过sudo执行的命令都会存在日志里面2.用法1.sudo -l 列出当前用户有哪些sudo权限 2.visudo -c 检查语法是否错误 3.visudo ...

  6. hdu1285 确定比赛名次(拓扑排序)

    有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道 ...

  7. Hat’s Words

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. bash脚本条件测试总结

    一.if语句的结构 分为以下三种:单分支.双分支.多分支 单分支if语句 if CONDITION is True: then 分支 fi 双分支if语句 if CONDITION is True: ...

  9. [DeeplearningAI笔记]ML strategy_2_4端到端学习

    机器学习策略-端到端学习 End-to-end deeplearning 觉得有用的话,欢迎一起讨论相互学习~Follow Me 2.9 什么是端到端学习-What is End-to-end dee ...

  10. 《Linux命令行与shell脚本编程大全》 第四章

    4.1 监测程序 1. ps  默认只显示运行在当前控制台下的属于当前用户的进程.  可以接很多选项,比如 -A表示所有进程  -e等. 2. ps -l  查看进程更多信息 UID:启动这些进程的用 ...