Coins
Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 37853   Accepted: 12849

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 10
1 2 4 2 1 1
2 5
1 4 2 1
0 0

Sample Output

8
4
  第一行输入,n,m分别表示n种硬币,m表示总钱数。
  第二行输入n个硬币的价值,和n个硬币的数量。
  输出这些硬币能表示的所有在m之内的硬币种数。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int dp[],pos[];
int a[],b[];
int k,x,n,m,ans;
int main()
{
while(scanf("%d%d",&n,&m) && n+m)
{
memset(dp,,sizeof(dp));
ans=;
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
for(int i=;i<n;i++)
{
scanf("%d",&b[i]);
}
dp[]=;
for(int i=;i<n;i++)
{
memset(pos,,sizeof(pos));
for(int j=a[i];j<=m;j++)
{
if(!dp[j] && dp[j-a[i]] && pos[j-a[i]]<b[i])
{
pos[j]=pos[j-a[i]]+;
dp[j]=;
ans++;
}
}
}
printf("%d\n",ans);
}
return ;
}
 
												

最新文章

  1. Ubuntu防火墙设置
  2. linux项目-之系统安装部署-cobbler
  3. Asp.net MVC生命周期
  4. typeof与GetType
  5. 第一篇 ERP是什么?-从道的层面浅谈我的理解
  6. Spring中使用quartz插件实现定时任务
  7. iOS系统弃用方法更新方法
  8. endnote X7参考文献缩进设置
  9. asp.net验证码的编写
  10. .NET并行计算和并发2-Foreground and Background Threads
  11. 从一个事件绑定说起 - DOM
  12. jeecg开发环境搭建
  13. linux下安装mysql环境
  14. HDU 1425 sort C语言实现快速排序
  15. Linux 系统安装配置PHP服务(源码安装)
  16. (转)c++一些知识点
  17. ubunttu-sh: 1: pause: not found
  18. 【洛谷4719】 动态dp(树链剖分,dp,矩阵乘法)
  19. Python自动化之跨域访问jsonp
  20. P2261 [CQOI2007]余数求和

热门文章

  1. hdu 1022 - 数据结构 栈
  2. 用@property (copy) NSMutableArray *array;会有什么问题?
  3. Web开发、原生开发、混合开发的区别优势:
  4. 通过JMeter来测试Quick Easy FTP Server的上传与下载性能
  5. Testin实验室:陌陌APP通过率为94.92% 基本满足移动社交需求
  6. thinkphp5项目--企业单车网站(四)
  7. 85.explicit作用
  8. ORA-01659: 无法分配超出 7 的 MINEXTENTS
  9. 反斜杠处理函数addslashes()和stripslashes()
  10. Centos7最小化安装后再安装图形界面