博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ-1742 Coins
阅读量:6693 次
发布时间:2019-06-25

本文共 1804 字,大约阅读时间需要 6 分钟。

Coins
Time Limit: 3000MS Memory Limit: 30000K
Total Submissions: 37959 Accepted: 12882

Description

People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar.One day Tony opened his money-box 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 101 2 4 2 1 12 51 4 2 10 0

Sample Output

84
 
1 #include
2 #include
3 #include
4 using namespace std; 5 int dp[100005]; 6 int main() 7 { 8 int n,m; 9 while(cin>>n>>m)10 {11 if(n==0&&m==0) break;12 memset(dp,0,sizeof(dp));13 int val[1005],num[1005];14 for(int i=1;i<=n;i++)15 cin>>val[i];16 for(int i=1;i<=n;i++)17 cin>>num[i];18 dp[0]=1;19 int sum[100005],ans=0;20 for(int i=1;i<=n;i++)21 {22 memset(sum,0,sizeof(sum));//sum数组是个关键,第i件物品出现的次数23 for(int j=val[i];j<=m;j++)24 {25 if(!dp[j]&&dp[j-val[i]]&&sum[j-val[i]]
 

 

 
 

转载于:https://www.cnblogs.com/ISGuXing/p/7215238.html

你可能感兴趣的文章
Mysql insert声明优化
查看>>
Scala学习(三)练习
查看>>
Linux时间同步
查看>>
【原版的:参赛作品】窥秘懒---android打开下拉手势刷新时代
查看>>
VirtualBox中虚拟Ubuntu添加新的虚拟硬盘
查看>>
Codeforces Round #311 (Div. 2) A. Ilya and Diplomas 水题
查看>>
BASE64 编码解码
查看>>
unity3d 读取usb摄像头
查看>>
总结eclipse中安装maven插件
查看>>
用SignalR 2.0开发客服系统[系列1:实现群发通讯]
查看>>
atitit。全局变量的设计与实现 java php的异同
查看>>
[C++]VisualAssistX中文注释提示错误 解决办法
查看>>
利用chorme调试手机网页
查看>>
网站性能优化:动态缩略图技术实现思路
查看>>
Tips and Examples Using FNDLOAD (DOC ID 735338.1)
查看>>
修改PHP上传文件大小限制的方法
查看>>
sql server 错误总结
查看>>
android获取View上某点的颜色
查看>>
unbuntu apahce 2 设置 多域名
查看>>
switf资源
查看>>