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. 小心指针被delete两次

    C++类中,有时候使用到传值调用(对象实体做参数),遇到这种情况,可要小心了!特别是当你所传值的对象生命周期较长,而非临时对象(生命周期段)的时候.来看看下面的情况: #include <ios ...

  2. Word2013死机的问题

    Word2013用公式编辑器经常死机,网上介绍方法.试试看https://zhidao.baidu.com/question/937023473910649252.html1.启动word2013 2 ...

  3. Android Cookie共享到WebView避免再次登录(保持登录状态)

    最近在做项目时用到了webview打开指定链接的网页,可已经把webview设置了cookie但始终跳转到登录页面,这明显是cookie没有设置成功导致webview没有将设置好的cookie发送出去 ...

  4. Amazon Kindle Device is hiring in Beijing Shanghai and Shenzhen!

    This is Angela from recruitment team of Amazon Kindle Device Software & Applications, we are exp ...

  5. golang的nil

    golang中什么样的类型可以赋值nil? 类型文档中有注定"uninitialized value is nil"的类型都可以赋值nil. golang的基本类型不能赋值nil: ...

  6. JVM规范小结

    JVM规范组成: 1. 字节码(ByteCode): 以Class或Interface为基本单位, 具有固定结构. 2. 指令集(InstructionSet): 每个指令用一个字节表示, 最多256 ...

  7. ubuntu server获取并自动设置最快镜像的方法

    一,安装方法1 add-apt-repository ppa:ossug-hychen/getfastmirrorapt-get install getfastmirror 如果添加了临时源,这样移除 ...

  8. 混合使用C和C++

    C++作为C语言的扩展集,几乎所有的C程序都可以在C++中编译和运行,但是要注意C程序中可能使用了C++中的关键字作为变量,比如在C中:int class = 0; 但这在C++中不行.出于方便性,我 ...

  9. C++ vector介绍

    <span style="font-family: Arial; ">在此总结一下模板vector的使用介绍</span> 标准库vector类型使用需要的 ...

  10. [shell基础]——if/for/while/until/case 语句

    for语句 do echo $loop done ` do echo $loop done for loop in `ls /tmp` do echo $loop done while语句 while ...