POJ-3624 01背包入门】的更多相关文章

初学DP,用贪心的思想想解题,可是想了一个多小时还是想不出. //在max中的两个参数f[k], 和f[k-weight[i]]+value[i]都是表示在背包容量为k时的最大价值 //f[k]是这个意思,就不用说了. //而f[k-weight[i]]+value[i]也表示背包容量为k时的最大价值是为什么呢? //首先,f[k-weight[i]]表示的是背包容量为k-weight[i]的容量,也就是说f[k-weight[i]] //表示的是容量还差weiht[i]才到k的价值,+walu…
POJ 2184 Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14657   Accepted: 5950 Description "Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - Cows with Guns by Dana Lyons The cows want to…
Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10200   Accepted: 3977 Description "Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - Cows with Guns by Dana Lyons The cows want to prove to…
Balance Time Limit: 1000 MS Memory Limit: 30000 KB 64-bit integer IO format: %I64d , %I64u Java class name: Main [Submit] [Status] [Discuss] Description Gigel has a strange "balance" and he wants to poise it. Actually, the device is different fr…
思路: 1.01背包 先找到所有奶牛身高和与B的差. 然后做一次01背包即可 01背包的容积和价格就是奶牛们身高. 最后差值一减输出结果就大功告成啦! 2. 搜索 这思路很明了吧... 搜索的确可以过- 3. 模拟! 0到1< < n 来一遍.(状压呗) 01背包的: // by SiriusRen #include <cstdio> #include <algorithm> using namespace std; int N,B,sum=0,h[25],f[1000…
Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 4257    Accepted Submission(s): 1757 Problem Description Recently, iSea went to an ancient country. For such a long time, it was…
题目引入: 有n个重量和价值分别为Wi,Vi的物品.从这些物品中挑选出总重量不超过W的物品,求所有挑选方案中的价值总和的最大值. 分析: 首先,我们用最普通的方法,针对每个物品是否放入背包进行搜索. #include<iostream> #include<stdio.h> using namespace std; int n,W; int w[100],v[100]; ///从第i个物品开始挑选总重量小于j的部分 int res(int i,int j)///i表示第i件物品,j表…
poj3624 Charm Bracelet 模板题 没有要求填满,所以初始化为0就行 #include<cstdio> #include<iostream> using namespace std; #define N 15010 int n,m,v[N],c[N],f[N]; int main(){ scanf("%d%d",&n,&m); ;i<=n;i++) scanf("%d%d",&v[i],&…
传送门:http://poj.org/problem?id=3624 题目大意:XXX去珠宝店,她需要N件首饰,能带的首饰总重量不超过M,要求不超过M的情况下,使首饰的魔力值(D)最大. 0-1背包入门题. 可构建状态转移方程: dp [ i ] [ v ]= max ( dp[ i-1 ] [ v ], dp[ i-1 ][ v- W[ i ] ]+d[ i ] ] ) 但是这样空间太大,可以用滚动数组解决. for(int i=1;i<=N;i++) { for(int j=M;j>=w[…
Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28365    Accepted Submission(s): 11562 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo…