POJ 1742
| Time Limit: 3000MS | Memory Limit: 30000K | |
| Total Submissions: 27580 | Accepted: 9335 |
Description
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
Output
Sample Input
3 10
1 2 4 2 1 1
2 5
1 4 2 1
0 0
Sample Output
8
4
Source
#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的更多相关文章
- hdu 2844 poj 1742 Coins
hdu 2844 poj 1742 Coins 题目相同,但是时限不同,原本上面的多重背包我初始化为0,f[0] = 1;用位或进行优化,f[i]=1表示可以兑成i,0表示不能. 在poj上运行时间正 ...
- [POJ 1742] Coins 【DP】
题目链接:POJ - 1742 题目大意 现有 n 种不同的硬币,每种的面值为 Vi ,数量为 Ni ,问使用这些硬币共能凑出 [1,m] 范围内的多少种面值. 题目分析 使用一种 O(nm) 的 D ...
- poj 1742(好题,楼天城男人八题,混合背包)
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 33269 Accepted: 11295 Descripti ...
- Coins HDU - 2844 POJ - 1742
Coins HDU - 2844 POJ - 1742 多重背包可行性 当做一般多重背包,二进制优化 #include<cstdio> #include<cstring> in ...
- 题解报告:hdu 2844 & poj 1742 Coins(多重部分和问题)
Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. On ...
- poj 1742 Coins (多重背包)
http://poj.org/problem?id=1742 n个硬币,面值分别是A1...An,对应的数量分别是C1....Cn.用这些硬币组合起来能得到多少种面值不超过m的方案. 多重背包,不过这 ...
- POJ 1742 hdu 2844 Coins
题目链接:http://poj.org/problem?id=1742 http://acm.hdu.edu.cn/showproblem.php?pid=2844 题目分类:动态规划 代码: #in ...
- poj 1742 Coins(dp之多重背包+多次优化)
Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...
- Coins (poj 1742 && hdu 2844 DP)
Language: Default Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 30047 Accepte ...
随机推荐
- rspec的一些常见用法
这里讲了如何安装rspec,安装使用rspec. 下面介绍一下rspec中常见的使用方法. 下面是一个最简单的测试用例,判断true是不是等于true,should_be是旧的用法,新用法推荐使用ex ...
- Linux查看文件以及文件夹的大小
df可以查看一级文件夹大小.使用比例.档案系统及其挂入点,但对文件却无能为力.du可以查看文件及文件夹的大小. df命令可以显示目前所有文件系统的可用空间及使用情形,请看下列这个例子: df命令可以查 ...
- QTP获取系统时间并自定义格式
function GetDateTime(Nowstr) Dim Currentdatetime Dim YY 'Year Dim MM ...
- poj 2312 Battle City
题目连接 http://poj.org/problem?id=1840 Battle City Description Many of us had played the game "Bat ...
- android开发系列之代码整洁之道
说起代码整洁之道,想必大家想到更多的是那本经典重构书籍.没错,记得当时自己读那本书的时候,一边结合项目实战,一边结合书中的讲解,确实学到了很多东西,对我自己的编码风格影响极深.随着时间的流逝,书中很多 ...
- Swift学习初步(一)
前几天刚刚将有关oc的教程草草的看了一遍,发现oc其实也不像传说的那么难.今天又开始马不停蹄的学习Swift因为我很好奇,到底苹果出的而且想要代替oc的编程语言应该是个什么样子呢?看了网上的一些中文教 ...
- 依网友要求发个修改award bios的方法(刷CPU微码)
注意本文修改的是award BIOS 首先看自己的CPUID是哪个代码,打开CPU-Z如下图红圈中就是,此CPUID就是067A,好了下面就可以开始准备工作 准备好BIOS文件,以及CPU微码文件.可 ...
- GNU make 总结 (五)
一.使用make更新静态库 静态库文件是一些.o文件的集合,在Linux中使用ar工具对它进行维护管理.一个静态库通常由多个.o文件组成,这些.o文件可独立的被作为一个规则的目标,库成员作为目标时需要 ...
- Mysql去除重复
常用的有两种方法,第一种就是select distinct name from table.但是有时候我们要返回多个字段时就用第二种方法select *, count(distinct name) f ...
- VS 与 SQLite数据库 连接
SQLite并没有一次性做到位,只有下载这些东西是不能放在vs2010中并马上使用的,下载下来的文件中有sqlite3.c/h/dll/def,还是不够用的.我们需要的sqlite3.lib文件并不在 ...