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. C-二维数组,多维数组

    -----二维数组      ->在数组定义当中,行数和列数需要用常量定义      ->在定义的时候如果没有数值进行填充,则补零      ->第一个数是行,第二个数是列     ...

  2. 用JS来计算百钱买百鸡

    怎样用一百块买一百只鸡?已知公鸡5块一只,母鸡3块一只,小鸡一块钱3只: 需要用到for循环嵌套,并且通过优化代码,可以加快运行效率. <!DOCTYPE html> <html l ...

  3. 未能加载文件或程序集“System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”

    最近用vs2012发布程序,然后将更新后的程序文件部署到服务器上,由于服务器上本来有此系统,所以只更新了修改的文件 . 进行系统登录时提示:未能加载文件或程序集“System.Web.Extensio ...

  4. Application 可以存储全局变量

    Application.Lock(); Application["Name"]="小亮" Application.UnLock(); Response.Writ ...

  5. jquery悬停tab

    <style> *{ margin:0; padding:0;} body { font:12px/19px Arial, Helvetica, sans-serif; color:#66 ...

  6. apache 反向代理配置(ubuntu)

    1.配置apache2的站点文件 cd /etc/apache2/site-avaliable sudo vim edy.conf 具体配置如下: # 反向代理配置 # 监听所有80端口的访问 < ...

  7. 1、工程log4j 配置

    ### set log levels ### log4j.rootLogger = debug,stdout,R ### 输出到控制台 ### log4j.appender.stdout = org. ...

  8. 慕课linux学习笔记(九)常用命令(6)

    关机与重启命令 Shutdown [选项] 时间 -c 取消前一个关机命令 -h 关机 -r 重启 Shutdown -r now 其他关机命令 Halt Poweroff Init 0 其他重启命令 ...

  9. liunx下安装mysql没有初始密码的解决方法

    #/etc/init.d/mysql stop #cd /usr/local/mysql #mysqld_safe --user=mysql --skip-grant-tables --skip-ne ...

  10. CC2530 PWM波形产生。

    1.使用TIM3_CC1,相关联引脚P1_7 #define GPIOPWM() do{P1SEL |= 0x80;}while(0);#define GPIOCLOSEPWM() do{P1SEL  ...