完全背包 poj 1384
来源:互联网 发布:关于网络的英语作文 编辑:程序博客网 时间:2024/05/20 17:23
#include<cstdio>
#include<cmath>
#include<iostream>
#include<conio.h>
using namespace std;
const int maxn=500;
const int maxdp=10010;
int p[maxn],w[maxn];
int dp[maxdp];
int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t); //次数
while(t--){
int w1,sum,n;scanf("%d%d%d",&w1,&sum,&n);
sum-=w1; //背包容量
for(int i=0;i<n;i++)scanf("%d%d",&p[i],&w[i]); //每种金币数据
memset(dp,-1,sizeof(int)*(sum+1)); //dp值清为-1 为完全背包的前提条件
dp[0]=0; //dp[0]为没有价值的情况 清为零 初始化
for(int i=0;i<n;i++){ //0-n
for(int j=w[i];j<=sum;j++){ //完全背包 j=w[i] w为金币的重量 自家
if(dp[j]!=-1&&dp[j-w[i]]!=-1)dp[j]=min(dp[j],dp[j-w[i]]+p[i]); //状态转移判断
else if(dp[j-w[i]]!=-1)dp[j]=dp[j-w[i]]+p[i];
}
}
if(dp[sum]==-1)puts("This is impossible."); //输出
else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[sum]);
}
}
- 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 (完全背包)
- 学习OpenCV例2-6
- poj1088滑雪搜索dfs
- 数列求和
- 散列(开放定址法)
- 01 背包 poj 3624
- 完全背包 poj 1384
- 开散列表及其查找算法的实现
- Visual Studio 2010——C#的通用对话框控件的使用
- 杭电ACM 1015 很笨的暴力解法
- poj 1276 完全背包
- python核心编程
- Windows下sqlplus “/as sysdba”登陆报“ORA-01031: insufficient privileges”处理
- Linux多线程编程(不限Linux)
- 每月自评之三:2013年3月