HDU 2602 (简单的01背包) Bone Collector

很标准的01背包问题

 1 //#define LOCAL
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include <cstring>
 5 using namespace std;
 6
 7 const int maxn = 1000 + 10;
 8 int w[maxn], v[maxn], dp[maxn];
 9
10 int main(void)
11 {
12     #ifdef LOCAL
13         freopen("2602in.txt", "r", stdin);
14     #endif
15
16     int T;
17     scanf("%d", &T);
18     while(T--)
19     {
20         int n, V;
21         scanf("%d%d", &n, &V);
22         for(int i = 0; i < n; ++i)
23             scanf("%d", &w[i]);
24         for(int i = 0; i < n; ++i)
25             scanf("%d", &v[i]);
26         memset(dp, 0, sizeof(dp));
27         for(int i = 0; i < n; ++i)
28             for(int j = V; j >= v[i]; --j)
29                 dp[j] = max(dp[j], dp[j-v[i]] + w[i]);
30         printf("%d\n", dp[V]);
31     }
32     return 0;
33 }

代码君

HDU 2602 (简单的01背包) Bone Collector

时间: 2024-12-26 09:55:43

HDU 2602 (简单的01背包) Bone Collector的相关文章

hdu2602 01背包Bone Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 40316    Accepted Submission(s): 16748 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone Collector&qu

hdu 1864 最大报销额 模型为简单的01背包

很简单的01背包,但是题目还是很蛋疼的注意题目中600,和1000这两个数,还有就是double和int的转换,1A了感觉还是不错的 /************************************************************************* > File Name: hdu1864.cpp > Author: yang > Mail:[email protected] > Created Time: 2014年08月23日 星期六 14:0

Bone Collector(杭电2602)(01背包)

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 31604    Accepted Submission(s): 13005 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo

HDU 1171 Big Event in HDU(母函数或01背包)

Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 44151    Accepted Submission(s): 15191 Problem Description Nowadays, we all know that Computer College is the biggest department

hdu 3466 Proud Merchants(0-1背包+排序)

题目来源:hdu 3466 Proud Merchants Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 3595 Accepted Submission(s): 1500 Problem Description Recently, iSea went to an ancient country. For

HDU 2546 饭卡(01 背包)

链接:http://acm.hdu.edu.cn/showproblem.php?pid=2546 思路:需要首先处理一下的的01背包,当饭卡余额大于等于5时,是什么都能买的,所以题目要饭卡余额最小,那预留5元(相当于饭卡余额为5)来买最贵的菜 然后对剩下n-1进行01背包dp才是正确的.但是还存在一个问题,那就饭卡初始余额小于5时,也要处理掉. 下面讲01背包(原型可以看大牛的背包九讲,本人也正在学习),定义dp[i][j]为买前i种菜品剩下j元时的最大消费值等于下面两中情况之一的值 有两种来

HDU 2546 饭卡(01背包裸题)

饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28562    Accepted Submission(s): 9876 Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无

HDU 5234 Happy birthday 01背包

题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5234 bc:http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=585&pid=1003 题解: 由于数据比较小,所以可以转化为判定性问题,即: dp[i][j][kk]表示走到i,j这一点时吃了kk重的蛋糕,转移方程只要考虑这一点的蛋糕吃和不吃两种情况(01背包) 代码: 1 #include<ios

hdu 2546 饭卡(0-1背包)

题目来源:hdu 2546 饭卡 饭卡 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 16645 Accepted Submission(s): 5797 Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后