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. springMVC+jpa配置之简单案例

    搭建springMVC+jpa的亲身经历,看着网上的博客,自己摸索着搭建框架结果错误一大堆.现在把流程走一遍,方便以后查看. 其中我遇到这样的一个问题:直接启动tomcat运行保存实体能通过,但是通过 ...

  2. Redhat 6环境下安装Oracle 12c的方法

    Step 1: 要在Linux上安装Oracle,需要在安装Oracle之前安装好相应的软件包,在不同操作系统环境下,对软件包的要求各不相同.具体对应的软件包,见官网文档:https://docs.o ...

  3. 多线程异步加载图片async_pictures

    异步加载图片 目标:在表格中异步加载网络图片 目的: 模拟 SDWebImage 基本功能实现 理解 SDWebImage 的底层实现机制 SDWebImage 是非常著名的网络图片处理框架,目前国内 ...

  4. SQL基础篇——如何搭建一个数据库

    特别提醒:所有的新建数据库,表,行,列都可以通过对象资源管理器操作,下面所讲的为查询操作方法 一.新建数据库 使用CREATE DATABASE语句建立数据库: 新建查询-- CREATE DATAB ...

  5. [SRH.Docker] HBase Java 第一天学习记录

    主要对HBase Table 的 简单操作, 直接上代码吧!!! http://pan.baidu.com/s/1hqzTTze       ui92

  6. MongoDB 数据类型

    MongoDB支持许多数据类型的列表下面给出: String : 这是最常用的数据类型来存储数据.在MongoDB中的字符串必须是有效的UTF-8. Integer : 这种类型是用来存储一个数值.整 ...

  7. 用Swift重写公司OC项目(Day1)--程序的AppIcon与LaunchImage如何设置

    公司之前的APP呢经过了两次重写,都是使用OC由本人独立开发的,不过这些东西我都不好意思说是自己写的,真心的一个字:丑!!! 客观原因来说主要是公司要的特别急,而且注重的是功能而非效果,公司的美工之前 ...

  8. 49.关于Quartus和ISE中ROM的初始化和仿真的一些小结

    最近在玩Altera的FPGA,当我用Quartus II自带的IP核生成ROM时,出现了各种问题,于是在网上各种查资料,终于解决了我的问题.这里做一下小结,方便自己日后查阅. Quartus II ...

  9. 用PHP对数据库数据进行删除

    显示页面: <body> <table width="100%" border="1" cellpadding="0" c ...

  10. ptypes中string类的空间分配

    问题描述:            在学习ptypes中string类的空间分配时,经常使分配的空间超出实际所需的空间 使用的分配函数是:_alloc函数 注:        在_alloc函数中调用了 ...