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 <stdio.h>
#include <algorithm>
#include <string.h> int dp[100005];
int sum[100005];
int v[105],c[105]; int main()
{
int i,j,k,n,m;
while(~scanf("%d%d",&n,&m),n+m)
{
for(i = 1;i<=n;i++)
scanf("%d",&v[i]);
for(i = 1;i<=n;i++)
scanf("%d",&c[i]);
memset(dp,0,sizeof(dp));
dp[0] = 1;
int ans = 0;
for(i=1;i<=n;i++)
{
memset(sum,0,sizeof(sum));
for(j = v[i];j<=m;j++)
{
if(!dp[j] && dp[j-v[i]] && sum[j-v[i]]<c[i])
{
dp[j] = 1;
sum[j] = sum[j-v[i]]+1;
ans++;
}
}
}
printf("%d\n",ans);
} return 0;
}

POJ1742:Coins(多重背包)的更多相关文章

  1. POJ1742 Coins[多重背包可行性]

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 34814   Accepted: 11828 Descripti ...

  2. $POJ1742\ Coins$ 多重背包+贪心

    Vjudge传送门 $Sol$ 首先发现这是一个多重背包,所以可以用多重背包的一般解法(直接拆分法,二进制拆分法...) 但事实是会TLE,只能另寻出路 本题仅关注“可行性”(面值能否拼成)而不是“最 ...

  3. POJ 3260 The Fewest Coins(多重背包+全然背包)

    POJ 3260 The Fewest Coins(多重背包+全然背包) http://poj.org/problem?id=3260 题意: John要去买价值为m的商品. 如今的货币系统有n种货币 ...

  4. HDU-2844 Coins(多重背包)

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

  5. POJ3260——The Fewest Coins(多重背包+完全背包)

    The Fewest Coins DescriptionFarmer John has gone to town to buy some farm supplies. Being a very eff ...

  6. POJ 1742 Coins(多重背包, 单调队列)

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

  7. HDU2844 Coins 多重背包

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

  8. HDu -2844 Coins多重背包

    这道题是典型的多重背包的题目,也是最基础的多重背包的题目 题目大意:给定n和m, 其中n为有多少中钱币, m为背包的容量,让你求出在1 - m 之间有多少种价钱的组合,由于这道题价值和重量相等,所以就 ...

  9. hdu2844 &amp; poj1742 Coin ---多重背包--两种方法

    意甲冠军:你有N种硬币,每个价格值A[i],每个号码C[i],要求. 在不超过M如果是,我们用这些硬币,有多少种付款的情况下,.那是,:1,2,3,4,5,....,M这么多的情况下,,你可以用你的硬 ...

随机推荐

  1. HDU 4810 这道题 是属于什么类型?

    统计每一位出现1的个数  求组合数 直接贴代码 #include <iostream> #include <cstdio> #include <cmath> #in ...

  2. 慕课linux学习笔记(六)常用命令(3)

    Find 命令 #搜索文件 Find [搜索范围] [搜索条件] e.g. find / -name isnstall.log 搜索速度会非常慢 避免大范围搜索,会非常耗费系统资源 Find是在系统当 ...

  3. django的model对象转化成dict

    今天发现一个掉渣天的方法,Django的forms包里面有一个方法:model_to_dict(),它可以将一个model对象转化成dict. In [1]: from apps.dormitory. ...

  4. Ubuntu下给Sublime Text 3添加用python3运行文件

    Ubuntu14.04: 菜单栏:Tools-Build System-New Build System { "cmd": ["python3", " ...

  5. ACM ICPC Team

    Link: https://www.hackerrank.com/challenges/acm-icpc-team/submissions/code/11617807 def count_max_to ...

  6. 使用Map/MapWhen扩展方法

    使用Map/MapWhen扩展方法 .NET Core中间件的注册和管道的构建(3) ---- 使用Map/MapWhen扩展方法 0x00 为什么需要Map(MapWhen)扩展 如果业务逻辑比较简 ...

  7. Scala学习笔记--隐式转换

    隐式转换的规则:1.无歧义规则:隐式转换唯有不存在其他可插入转换的前提下才能插入  若编译器有两种方法修正x+y 如convert1(x)+y,convert2(x)+y,会报错2.单一调用规则:只尝 ...

  8. Form表单插件jquery.form.js

    常常使用到这个插件,但是老忘记怎么使用,现在对大家写的进行一定的整合. 使用插件实例: 一般的使用方法 <!-- 引入jquery文件 --> <script src="h ...

  9. Extjs4.0.7 MVC Architecture异常

    uncaught exception: Ext.Loader is not enabled, so dependencies    cannot be resolved dynamically. Mi ...

  10. cf C. Cupboard and Balloons

    http://codeforces.com/contest/342/problem/C #include <cstdio> #include <cstring> #includ ...