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. 辛星浅析raid

    我们来分析一下影响计算机性能的主要组件,主要就是CPU.主板的总线IO.内存IO.硬盘IO.网卡IO等等,并且如今CPU的性能已经非常好了,可是计算机的总体的IO性能却较低,严重影响了计算机的性能,如 ...

  2. Upgrade to postgresql 9.5

        Add postgresql apt repo.. according to your distribution (utopic, trusty, jessie, wheezy and etc ...

  3. c语言-完全背包问题

    完全背包问题 问题:有N种物品和一个容量为V的背包,每种物品都有无限件可用.第i种物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大. 分 ...

  4. windows下通过VNC图形化訪问Ubuntu桌面环境

    要在windows下图形化訪问Ubuntu或其他Linux系统桌面环境有非常多方法.我比較喜欢的是使用VNC服务,须要在Ubuntu下安装vncserver和在windows下安装client訪问工具 ...

  5. Cadence SPB 16. 6 安装步骤

    1.首先下载Cadence Allegro SPB orCAD16. 6 安装包,单击我,下载之后运行其中的setup.exe,然后先安装第一项License Manager

  6. Hadoop 服务器配置的副本数量 管不了客户端

    副本数由客户端的参数dfs.replication决定(优先级: conf.set > 自定义配置文件 > jar包中的hdfs-default.xml)如果前两个都没有,就用最后一个ja ...

  7. Linux 下编译安装OpenCV(zhuanzai)

    http://www.cnblogs.com/emouse/archive/2013/02/22/2922940.html Cmake的安装 OpenCV 2.2以后版本需要使用Cmake生成make ...

  8. eclipse如何查问题?

    问题:从SVN上拉了一个项目,莫名奇妙就报错?看着就很纠结 解决之道:在Window下拉菜单show View 找到Problems 就可以查到具体的原因,我的这个是需要添加一个tomcat服务器

  9. Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.

    运行/usr/local/webserver/php/bin/phpize时出现: Configuring for: PHP Api Version: 20041225 Zend Module Api ...

  10. kbmmw 5 的日志备份功能简介

    kbmmw 自从4.8.2 版本里增加了日志管理以后,随着版本升级,增加了很多功能,使用方法也有所改变. 功能也越来越强大. 今天说一下 kbmmw5 里面的日志备份,顺便演示一下新的使用方法. 我们 ...