POJ 1384 完全背包问题
来源:互联网 发布:淘宝买止咳水的暗语 编辑:程序博客网 时间:2024/05/20 16:35
http://poj.org/bbs?problem_id=1384
完全背包问题,训练赛上没有注意初始化,悲催的结局中...
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
#define manx 505
#define inf 99999999
int x[manx],y[manx];
int dp[10009];
int main(){
int t,e,f;
scanf("%d",&t);
while(t--){
int n,flag=0;
scanf("%d%d%d",&e,&f,&n);
int sum=f-e;
for(int i=0;i<550;i++)
x[i]=y[i]=0;
for(int i=0;i<=10009;i++) // 初始化问题
dp[i]=inf;
dp[0]=0;
for(int i=1;i<=n;i++){
scanf("%d%d",&x[i],&y[i]);
}
for(int i=1;i<=n;i++){ // 完全背包状态转移方程
for(int j=y[i];j<=sum;j++){
dp[j]=min(dp[j],dp[j-y[i]]+x[i]);
}
}
if(dp[sum]==inf) printf("This is impossible.\n");
else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[sum]);
}
}
- poj 1384 完全背包问题
- POJ 1384 完全背包问题
- POJ 1384 完全背包问题
- POJ 1384 Piggy-Bank(完全背包问题)
- poj 1384 完全背包问题 dp
- POJ-1384 Piggy bank 完全背包问题
- POJ 1384 Piggy Bank 完全背包问题
- POJ-1384 完全背包
- POJ 1384 完全背包
- poj 1384完全背包
- 完全背包 poj 1384
- poj 1384完全背包
- poj 1384 完全背包
- 完全背包 POJ 1384
- POJ 1384 完全背包
- POJ-1384 完全背包
- POJ 1384 【完全背包】
- POJ 1384【完全背包】
- 微软不为人知的18个秘密
- stl容器学习总结
- poj1694
- 关于SVD的一些参考文献
- 黑马程序员------流操作的基本规律
- POJ 1384 完全背包问题
- java-API文档如何查阅
- SOA在当今中国企业的发展现状
- Android OpenGL ES 2.0画立方体JNI实现
- 由中序和后序确定一棵二叉树
- POJ2007 Scrambled Polygon
- Description has only two Sentences
- 缓存
- HDU 4431 Mahjong (模拟) #by Plato