poj 1384 完全背包
来源:互联网 发布:sm3算法 编辑:程序博客网 时间:2024/05/20 17:07
完全背包,注意初始化的细节dp【0】=0;
这道题要求的是恰好装满背包的最小的价值,所以初始状态下,只有dp[0]满足条件,即容量为0的背包可能被价值为0的东西(即木有东西)装满背包,其他容量的背包均没有合法解,都是无穷大,之所以是恰好装满是因为贮蓄罐的增重是一定的
#include<stdio.h>#include<string.h>int dp[10000];int w[505],v[505];int min(int a,int b){return a<b?a:b;}int main(){int t,e,f,i,j,k,n;scanf("%d",&t);while(t--){scanf("%d%d",&e,&f);scanf("%d",&n);for(i=1;i<=n;i++)scanf("%d%d",&v[i],&w[i]);int V=f-e;for(i=1;i<=V;i++) dp[i]=10000000; dp[0]=0;for(i=1;i<=n;i++){for(j=0;j<=V;j++){if(j>=w[i])dp[j]=min(dp[j-w[i]]+v[i],dp[j]);}}if(dp[V]!=10000000)printf("The minimum amount of money in the piggy-bank is %d.\n",dp[V]);else printf("This is impossible.\n");}}
- POJ-1384 完全背包
- POJ 1384 完全背包
- poj 1384完全背包
- 完全背包 poj 1384
- poj 1384完全背包
- poj 1384 完全背包
- 完全背包 POJ 1384
- POJ 1384 完全背包
- POJ-1384 完全背包
- POJ 1384 【完全背包】
- POJ 1384【完全背包】
- poj 1384 完全背包
- poj 1384 完全背包问题
- POJ 1384 完全背包问题
- POJ 1384 完全背包问题
- poj 1384 Piggy-Bank 完全背包
- poj 1384Piggy-Bank(完全背包)
- POJ 1384 Piggy-Bank (完全背包)
- poj 2536 二分匹配
- poj 2537 DP
- 关于分组背包
- hdu 3535 终极版解题报告
- zstu 1032 拆分物品 再01背包
- poj 1384 完全背包
- poj 1252 完全背包
- poj 3468 A Simple Problem with Integers
- poj 2063 多次完全背包
- hdu 3183 RMQ
- nlogn 最长不下降子序列
- jquery checkbox多选最简单的写法
- poj 3260 hdu 3591 多重背包+完全背包
- poj 1742 多重背包可行性