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. eclipse注释模板修改

    http://swiftlet.net/archives/1199 以下为模板文件 <?xml version="1.0" encoding="UTF-8" ...

  2. 关于java中根据身份证求生日和年龄的问题

    /*这个也没什么大的功能,也没什么安全验证,只是对输入的身份证号码的长度进行了验证.其他的功能可以自己添加.*/import java.util.*; import java.util.Scanner ...

  3. DEV GridControl 导出到Excel

    SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "导出Excel"; sa ...

  4. ASP.Net MVC与WebForm的区别

  5. mysql查询分组归类函数-group_concat,通常与group_by一起使用

    select a.`name`,group_concat(b.name SEPARATOR'.') as persons from `group` as a,`person` as b,`person ...

  6. SATA接口硬盘加密器

    加密卡置于主板与硬盘.光驱之间,透明实时地对写入数据进行加密,对读出数据进行解密,有效防止信息被窃.未经授权的阅读和修改,以及硬盘.光盘丢失.被盗.废弃.非法用户访问而引发的敏感信息泄密问题,为用户打 ...

  7. Convert.ToInt32()和int.Parse()的区别

    (1)Convert.ToInt32(null)会返回0而不会报异常,但int.Parse(null)则会产生异常 (2)Convert.ToInt32("")和int.Parse ...

  8. python进行base64编解码

    [转] 直接上代码 import base64 fin = open(r"D:\2.zip", "rb") fout = open(r"D:\2.x. ...

  9. Session与Cookie间不得不说的一些事

    在很久很久以前,刚有浏览器和网页的时候,web开发者发现了一个问题,我必须要在客户端这边保存一些东西才能实现某些功能,比如大家喜闻乐见的购物车.用户登录.自动登陆等.但是客户端只有一个浏览器,怎么在用 ...

  10. nodejs 保存 payload 发送过来的文件

    1:接受文件 http://stackoverflow.com/questions/24610996/how-to-get-uploaded-file-in-node-js-express-app-u ...