Coins
Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 27580   Accepted: 9335

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

Source

 
定义dp[i]为目前为止装满i容量最多剩余多少个当前面值的
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int MAX_N = ;
const int MAX_M = 1e5 + ;
int N, M;
int v[MAX_N], c[MAX_N];
int dp[MAX_M]; void solve() {
dp[] = ;
for(int i = ; i <= N; ++i) {
for(int j = ; j <= M; ++j) {
if(dp[j] >= ) {
dp[j] = c[i];
}
else if(j < v[i] || dp[j - v[i]] <= ) {
dp[j] = -;
} else {
dp[j] = dp[j - v[i]] - ;
} }
} int ans = ;
for(int i = ; i <= M; ++i) {
ans += dp[i] >= ;
//printf("%d ",dp[i]);
} printf("%d\n", ans);
}
int main()
{
// freopen("sw.in", "r", stdin);
while(~scanf("%d%d", &N, &M) && (N + M)) {
memset(dp, -, sizeof(dp));
for(int i = ; i <= N; ++i) {
scanf("%d", &v[i]);
}
for(int i = ; i <= N; ++i) {
scanf("%d", &c[i]);
} solve();
}
//cout << "Hello world!" << endl;
return ;
}

POJ 1742的更多相关文章

  1. hdu 2844 poj 1742 Coins

    hdu 2844 poj 1742 Coins 题目相同,但是时限不同,原本上面的多重背包我初始化为0,f[0] = 1;用位或进行优化,f[i]=1表示可以兑成i,0表示不能. 在poj上运行时间正 ...

  2. [POJ 1742] Coins 【DP】

    题目链接:POJ - 1742 题目大意 现有 n 种不同的硬币,每种的面值为 Vi ,数量为 Ni ,问使用这些硬币共能凑出 [1,m] 范围内的多少种面值. 题目分析 使用一种 O(nm) 的 D ...

  3. poj 1742(好题,楼天城男人八题,混合背包)

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 33269   Accepted: 11295 Descripti ...

  4. Coins HDU - 2844 POJ - 1742

    Coins HDU - 2844 POJ - 1742 多重背包可行性 当做一般多重背包,二进制优化 #include<cstdio> #include<cstring> in ...

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

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

  6. poj 1742 Coins (多重背包)

    http://poj.org/problem?id=1742 n个硬币,面值分别是A1...An,对应的数量分别是C1....Cn.用这些硬币组合起来能得到多少种面值不超过m的方案. 多重背包,不过这 ...

  7. POJ 1742 hdu 2844 Coins

    题目链接:http://poj.org/problem?id=1742 http://acm.hdu.edu.cn/showproblem.php?pid=2844 题目分类:动态规划 代码: #in ...

  8. poj 1742 Coins(dp之多重背包+多次优化)

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

  9. Coins (poj 1742 &amp;&amp; hdu 2844 DP)

    Language: Default Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 30047   Accepte ...

随机推荐

  1. ruby 笔记

    symbol 不能有- 'data-turbolinks-track' => true stop rails –s kill -INT $(cat tmp/pids/server.pid) cl ...

  2. 分享我常用的一些JS验证和函数

    下面是我常用一些JS验证和函数,有一些验证我直接写到了对象的属性里面了,可以直接通过对象.方法来调用//浮点数除法运算 function fdiv(a, b, n) { if (n == undefi ...

  3. 应用程序域(Application Domain)

    应用程序域为隔离正在运行的应用程序提供了一种灵活而安全的方法. 应用程序域通常由运行时宿主创建和操作. 有时,您可能希望应用程序以编程方式与应用程序域交互,例如想在不停止应用程序运行的情况下卸载某个组 ...

  4. ANT编译build.xml

    一,体验ant就像每个语言都有HelloWorld一样,一个最简单的应用能让人感受一下Ant1,首先你要知道你要干什么,我现在想做的事情是:编写一些程序编译它们把它打包成jar包把他们放在应该放置的地 ...

  5. Python学习——struct模块的pack、unpack示例

    he struct module includes functions for converting between strings of bytes and native Python data t ...

  6. [转]论window和Linux之长短

    论window和Linux之长短 王垠 http://www.kerneltravel.net/jiqiao/whyLinux.htm — 摈弃 Windows 低效率的工作方式,发掘 Linux 身 ...

  7. RTLviewer与TechnologyMapViewer的区别?

    区别: 1.QUARTUS II 中往往要查看RTL Viewer,其实RTLview是编译后的结果,显示的图形都是调用标准单元的结果,这是和思维有关联的显示结果,跟工艺库,FPGA类型,都没有关系: ...

  8. ED/EP简介

    ED:electronic Deposit,电子存折 EP:electronic Purse,电子钱包 PIN:personal identification number,个人识别码 MAC:Mes ...

  9. c++函数内部声明函数,在函数外面实现函数是可以的

    这个具体有什么用我也不大清楚,只知道可以这样 #include <iostream> //#include "header1.h" using namespace st ...

  10. 软件工程随堂小作业——最优惠价钱(C++)

    一.设计思路 前提,没有买重复书的情况是最优惠的.总共买n本书,可以分解成5k+(n-5k),k=0,1,2,...1.如果k=0,n本不重复的价钱是最优惠的:2.如果k=1,算出每一种情况的折扣并比 ...