Problem Description
Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact price(without change) and he known the price would not more than m.But he didn't know the exact price of the watch.

You are to write a
program which reads n,m,A1,A2,A3...An and C1,C2,C3...Cn corresponding to
the number of Tony's coins of value A1,A2,A3...An then calculate how
many prices(form 1 to m) Tony can pay use these coins.

 
Input
The
input contains several test cases. The first line of each test case
contains two integers n(1 ≤ n ≤ 100),m(m ≤ 100000).The second line
contains 2n integers, denoting A1,A2,A3...An,C1,C2,C3...Cn (1 ≤ Ai ≤
100000,1 ≤ Ci ≤ 1000). The last test case is followed by two zeros.
 
Output
For each test case output the answer on a single line.
 
Sample Input
3 10
1 2 4 2 1 1
2 5
1 4 2 1
0 0
Sample Output
8
4
 
题目就是让你用所给的 种类一定,数目一定的硬币,看能组成的数字有那先(当然,询问范围是1 ~ m)
还是列出已知条件,硬币的种类,每类的个数,查询范围(1 ~ m)
在多重背包里,我们用到的条件有:背包容量,物品种类,物品每类的数量, 物品每类所用的体积大小
抽象这道题目,我们直观的知道,硬币的种类,硬币每类的数量,每类硬币的面值。题目里只有这 3 个条件, 做背包问题一定会涉及“物品占用体积的大小”,而这道题完全没有提 ,因为我们最后求的是所能组成面值的总数。 这里提一下,我们的面值,既可以当作物品的重量,又可以当作物品占的体积
 
 #include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm> using namespace std;
const int max_size = + ;
const int MAX = ;
int dp[max_size];
bool vis[max_size]; int main()
{
//1.将问题的模型抽象出来
int cnt, vol;
int val[MAX];
int num[MAX];
while(scanf("%d %d", &cnt, &vol) != EOF)
{
memset(dp, , sizeof(dp));
memset(vis, false, sizeof(vis));
if(cnt == && vol == )
break;
for(int i = ; i < cnt; i++)
scanf("%d", val+i);
for(int i = ; i < cnt; i++)
scanf("%d", num+i); for(int i = ; i < cnt; i++)
{
if(val[i] * num[i] >= vol)
{
//CompletePack(val[i], val[i]); //那么多的价值,那么多的占用? for(int j = val[i]; j <= vol; j++) ///多重背包这里错了两次了,要注意,昨天找了一晚上
{
dp[j] = max(dp[j], dp[j - val[i]] + val[i]);
vis[dp[j]] = true;
}
continue;
}
int k = ;
while(k < num[i])
{
//ZeroOnePack(k*val[i], k*val[i]);
for(int j = vol; j - k * val[i] >= ; j--)
{
dp[j] = max(dp[j], dp[j-k*val[i]] + k*val[i]);
vis[dp[j]] = true;
}
num[i] -= k;
k *= ;
}
//ZeroOnePack(num[i]*val[i], num[i]*val[i]);
for(int j = vol; j - num[i]*val[i] >= ; j--)
{
dp[j] = max(dp[j], dp[j - num[i]*val[i]] + num[i]*val[i]);
vis[dp[j]] = true;
}
} int ans = ;
for(int i = ; i <= vol; i++)
{
ans += (vis[i] == true) ? : ;
}
printf("%d\n", ans);
}
return ;
}

最新文章

  1. Linux下UPnP sample分析
  2. 关于AngularJS(1)
  3. iOS开发之GCD
  4. VS2010中,无法嵌入互操作类型“……”,请改用适用的接口的解决方法(转自网络)
  5. iOS10新特性
  6. c#中的事件
  7. 关于在for循环中绑定事件打印变量i是最后一次。
  8. 浅谈配置chrome浏览器允许跨域操作的方法
  9. 统计机器学习(statistical machine learning)
  10. Django 学习笔记之二 基本命令
  11. 【转】android-support-v7-appcompat.jar 的安装及相关问题解决 --- 汇总整理
  12. struts1、ajax、jquery、json简单实例
  13. Python字符串格式符号含义
  14. 常用类:String,StringBuffer,StringBuilder
  15. Office开发必备知识----为什么要释放非托管Com资源
  16. jar的打包与共享
  17. 精读JavaScript模式(二)
  18. OpenCV 学习笔记03 findContours函数
  19. 《C++ Primer Plus》第15章 友元、异常和其他 学习笔记
  20. Java设计模式之生产者消费者模式

热门文章

  1. NYOJ之Binary String Matching
  2. php JS和JQ
  3. Error parsing &#39;file:///media/RHEL_5.5\\ x86_64\\ DVD/Server&#39;
  4. 对Cookie和Session的深入理解
  5. 攻城狮在路上(叁)Linux(二十)--- Linux磁盘格式化
  6. zTree v3.5配置
  7. 在ASP.NET 5中使用SignalR
  8. PMP 第三章 单个项目的项目管理标准
  9. list[C++]
  10. 映射一对多双向关联关系 cascade、inverse、属性