HDU 1114(多重背包)
来源:互联网 发布:椭圆齿轮设计软件 编辑:程序博客网 时间:2024/06/06 15:46
Description
But there is a big problem with piggy-banks. It is not possible to determine how much money is inside. So we might break the pig into pieces only to find out that there is not enough money. Clearly, we want to avoid this unpleasant situation. The only possibility is to weigh the piggy-bank and try to guess how many coins are inside. Assume that we are able to determine the weight of the pig exactly and that we know the weights of all coins of a given currency. Then there is some minimum amount of money in the piggy-bank that we can guarantee. Your task is to find out this worst case and determine the minimum amount of cash inside the piggy-bank. We need your help. No more prematurely broken pigs!
Input
Output
Sample Input
310 11021 130 5010 11021 150 301 6210 320 4
Sample Output
The minimum amount of money in the piggy-bank is 60.The minimum amount of money in the piggy-bank is 100.This is impossible.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1000000;
const int inf = 999999999;
int dp[N], v[N], w[N];
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
for(int i=1; i<=N; i++)
{
dp[i]=inf;
}
int e, f, n;
scanf("%d %d", &e, &f);
scanf("%d", &n);
for(int i=0;i<n;i++)
{
scanf("%d %d", &v[i], &w[i]);
}
dp[0]=0;
for(int i=0;i<n;i++)
{
for(int j=w[i];j<=(f-e)+10;j++)
{
if(dp[j-w[i]]>=0&&dp[j]>dp[j-w[i]]+v[i])
{
dp[j]=dp[j-w[i]]+v[i];
}
}
}
if(dp[f-e]!=inf)
{
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[f-e]);
}
else
{
printf("This is impossible.\n");
}
}
return 0;
}
- HDU 1114(多重背包)
- hdu 1114 多重背包
- hdu 3732(多重背包)
- hdu-Coins(多重背包)
- hdu(1171)多重背包
- hdu 2844(多重背包)
- hdu 2191(多重背包)
- HDU 2191 (多重背包)
- HDU 2844(多重背包)
- HDU-2191-(多重背包)
- HDU--2191(多重背包)
- HDU 2844(多重背包)
- Big Event in HDU (多重背包)
- hdu 1059 Dividing (多重背包)
- HDU 2844 Coins(多重背包)
- hdu 1059 Dividing (多重背包 )
- hdu 2844 Coins (多重背包)
- hdu 2844 Coins(多重背包优化)
- 转载:Web服务器和应用服务器的区别
- Mickey序列密码算法的c语言实现
- {HTML5学习图谱}随着微信小程序的出现,HTML5将会炙手可热!
- task0001第六部分之两列布局
- Maximum Depth of Binary Tree(二叉树的最大深度)
- HDU 1114(多重背包)
- 关于构造器
- [3D基础]理解计算机3D图形学中的坐标系变换
- LuaApi
- pat 1030. 完美数列
- QsciScintilla的使用方法总结(一个很好用的文本编辑器库)
- 使用Hive
- 十步完全理解 SQL
- Java_web(spring+springMVC的总体步骤)