完全背包问题
来源:互联网 发布:商标查询软件下载 编辑:程序博客网 时间:2024/05/18 03:04
#include<iostream>
#include<string>
using namespace std;
#define min(a,b) a<b?a:b
int w[501],p[501];
int f[100001];
int main()
{
int t,i,j,n,a,b,MAX;
freopen("D:\\input.txt","r",stdin);
cin>>t;
while(t--)
{
cin>>a>>b;
MAX=b-a;
cin>>n;
for(i=0;i<n;i++)
{
cin>>p[i]>>w[i];
}
for(i=0;i<=100000;i++)
{
f[i]=1000000;
}
f[0]=0;
for(i=0;i<n;i++)
{
for(j=w[i];j<=MAX;j++)
{
f[j]=min(f[j],f[j-w[i]]+p[i]);
}
}
if(f[MAX]<1000000)
{
cout<<"The minimum amount of money in the piggy-bank is "<<f[MAX]<<'.'<<endl;
}
else
cout<<"This is impossible."<<endl;
}
return 0;
}
0 0
- 背包问题-完全背包-背包问题
- 01背包 完全背包问题
- 背包问题2:完全背包
- 01背包+完全背包问题
- nyoj311完全背包(完全背包问题)
- 完全背包问题
- 完全背包问题
- 完全背包问题
- 完全背包问题
- 完全背包问题
- P02: 完全背包问题
- 完全背包问题、、、
- P02: 完全背包问题
- 完全背包问题
- P02: 完全背包问题
- 完全背包问题
- P02: 完全背包问题
- 完全背包问题总结
- C语课设心得分享(三)
- 广州国际旅游展
- 火狐的poster工具
- iOS 优化内存(四)何时用self
- uploadify java上传图片
- 完全背包问题
- 简单创建标签栏
- javascript:用正则表达式替换字符串中满足要求的全部内容
- 母函数问题
- iOS 优化内存(五)开发流程总结
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- JUnit运行报错java.lang.NoClassDefFoundError: org/junit/rules/TestRule
- Ajax asp.net 导入Excel
- hduoj1048(The Hardest Problem Ever)