Coins
Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 32776   Accepted: 11131

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
#include"cstdio"
#include"cstring"
using namespace std;
const int MAXN=;
int dp[MAXN];
int n,m;
int A[MAXN];
int C[MAXN];
int main()
{
while(scanf("%d%d",&n,&m)!=EOF&&(n||m))
{
memset(dp,-,sizeof(dp));
for(int i=;i<n;i++) scanf("%d",&A[i]);
for(int i=;i<n;i++) scanf("%d",&C[i]);
dp[]=;
for(int i=;i<n;i++)
for(int j=;j<=m;j++)
if(dp[j]>=)
{
dp[j]=C[i];
}
else if(j<A[i]||dp[j-A[i]]<=)
{
dp[j]=-;
}
else
{
dp[j]=dp[j-A[i]]-;
}
int ans=;
for(int i=;i<=m;i++)
if(dp[i]>=) ans++;
printf("%d\n",ans);
} return ;
}

POJ1742(多重部分和问题:模板题)的更多相关文章

  1. POJ 2289 Jamie's Contact Groups 【二分】+【多重匹配】(模板题)

    <题目链接> 题目大意: 有n个人,每个人都有一个或者几个能够归属的分类,将这些人分类到他们能够归属的分类中后,使所含人数最多的分类值最小,求出该分类的所含人数值. 解题分析: 看到求最大 ...

  2. POJ_1742_Coins_(动态规划,多重部分和)

    描述 http://poj.org/problem?id=1742 n种不同面额的硬币 ai ,每种各 mi 个,判断可以从这些数字值中选出若干使它们组成的面额恰好为 k 的 k 的个数. 原型: n ...

  3. POJ1742 coins 动态规划之多重部分和问题

    原题链接:http://poj.org/problem?id=1742 题目大意:tony现在有n种硬币,第i种硬币的面值为A[i],数量为C[i].现在tony要使用这些硬币去买一块价格不超过m的表 ...

  4. hdu 2191 悼念512汶川大地震遇难同胞 【多重背包】(模板题)

    题目链接:https://vjudge.net/problem/HDU-2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活                                   ...

  5. HDU 2191 珍惜现在,感恩生活(多重背包模板题)

    多重背包模板题 #include<iostream> #include<cstring> #include<algorithm> using namespace s ...

  6. 多重部分和 poj1742

    Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...

  7. COJ 0557 4013多重部分和问题

    4013多重部分和问题 难度级别:B: 运行时间限制:2000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 n种大小不同的数字 Ai,每种各Mi个,判断是否可以从 ...

  8. HDU2844(多重部分和)

    Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  9. 题解报告:hdu 2844 & poj 1742 Coins(多重部分和问题)

    Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. On ...

随机推荐

  1. hdu5379||2015多校联合第7场1011 树形统计

    pid=5379">http://acm.hdu.edu.cn/showproblem.php? pid=5379 Problem Description Little sun is ...

  2. [转]eclipse查看某个java类属于哪个jar包

    原文地址:https://blog.csdn.net/csdnliuxin123524/article/details/73572836 在eclipse界面直接按ctrl+shift+t,弹出以下界 ...

  3. 前端UI框架整理

    JQuery Jquery官网:http://jquery.com/ jQuery是一个快速,小巧,且功能丰富的JavaScript库. Jquery-1.11.3.min.js 压缩版:http:/ ...

  4. Andriod三步学会安卓自己定义视图及其属性

    第一步:自己定义属性 第二步:自己定义控件解析属性 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcm5adW9adW8=/font/5a6L5L2T/fo ...

  5. git学习(4)---工作流

    一.目的 前三章介绍了git工具本身的操作,主要包含本地仓库操作和远程库操作两部分内容.接下来,我们将介绍怎样使用git进行项目开发,也叫做git工作流. git工作流分为三种模式:共享远程库模式.独 ...

  6. .Net Core表单定义

    创建表单 <form asp-controller="Account" asp-action="Login" asp-route-returnurl=&q ...

  7. Spring与JDK版本不一致引发问题Caused by: java.lang.IllegalArgumentException

    tomcat启动一个spring的项目,tomcat使用8.5,JDK使用1.8,Spring使用3.0,启动之后报错 Caused by: java.lang.IllegalArgumentExce ...

  8. JavaScript中批量设置Css样式

    设置 input 元素的  属性: document.getElementsByTagName("INPUT")[0].setAttribute("属性",&q ...

  9. 第 2 章 第 1 题 同位词问题 下问 Multimap实现

    问题分析 输入:一个任意的单词和一个内含多个乱序单词的字典文件 输出:该单词在字典中的所有同位词 约束:允许事先对字典进行预处理 解决思路 上问的程序有个缺点 - 我们必须遍历完整个字典文件才能输出所 ...

  10. LINQ to SQL 语句(1)之 Where

    LINQ to SQL 语句(1)之 Where Where 操作 适用场景:实现过滤,查询等功能. 说明:与 SQL 命令中的 Where 作用相似,都是起到范围限定也就是过滤作用的 ,而判断条 件 ...