动态规划(背包问题):POJ 1742 Coins
| Time Limit: 3000MS | Memory Limit: 30000K | |
| Total Submissions: 32955 | Accepted: 11199 |
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
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
Sample Input
3 10
1 2 4 2 1 1
2 5
1 4 2 1
0 0
Sample Output
8
4
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int num[],v[];
int dp[][];
int main()
{
int n,m,now,pre;
while(~scanf("%d%d",&n,&m)&&n&&m)
{
for(int i=;i<=n;i++)scanf("%d",&v[i]);
for(int i=;i<=n;i++)scanf("%d",&num[i]);
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++){
now=i%;pre=(i-)%;
dp[now][]=;
for(int j=;j<=m;j++){
if(dp[pre][j]<=num[i-])dp[now][j]=;
if(j>=v[i]&&dp[now][j-v[i]]+<=num[i])
dp[now][j]=min(dp[now][j],dp[now][j-v[i]]+);
}
} int ans=;
for(int i=;i<=m;i++)
if(dp[now][i]<=num[n])
ans++; printf("%d\n",ans);
}
return ;
}
动态规划(背包问题):POJ 1742 Coins的更多相关文章
- hdu 2844 poj 1742 Coins
hdu 2844 poj 1742 Coins 题目相同,但是时限不同,原本上面的多重背包我初始化为0,f[0] = 1;用位或进行优化,f[i]=1表示可以兑成i,0表示不能. 在poj上运行时间正 ...
- 题解报告: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 【DP】
题目链接:POJ - 1742 题目大意 现有 n 种不同的硬币,每种的面值为 Vi ,数量为 Ni ,问使用这些硬币共能凑出 [1,m] 范围内的多少种面值. 题目分析 使用一种 O(nm) 的 D ...
- poj 1742 Coins (动态规划,背包问题)
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 32977 Accepted: 11208 Descripti ...
- poj 1742 Coins(dp之多重背包+多次优化)
Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...
- POJ 1742 Coins(多重背包, 单调队列)
Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...
- Poj 1742 Coins(多重背包)
一.Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dolla ...
- poj 1742 Coins (多重背包)
http://poj.org/problem?id=1742 n个硬币,面值分别是A1...An,对应的数量分别是C1....Cn.用这些硬币组合起来能得到多少种面值不超过m的方案. 多重背包,不过这 ...
- POJ 1742 Coins (多重背包)
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 28448 Accepted: 9645 Descriptio ...
随机推荐
- mxnet运行时遇到问题及解决方法
1.训练好模型之后,进行预测时出现这种错误: mxnet.::] src/ndarray/ndarray.cc:: Check failed: ,) to.shape=(,) 这种问题的解决方法,在全 ...
- rabbitmq 消息持久化
rabbitmq 消息持久化 2016-02-18 11:19 224人阅读 评论(0) 收藏 举报 分类: 综合(15) 版权声明:本文为博主原创文章,未经博主允许不得转载. 二: 任务分发 & ...
- 【css面试题】三个DIV要求水平对齐,左右两个DIV宽度固定为100px,中间那个DIV充满剩余的宽度(至少2种方法)
这是我在一家公司面试时遇到的问题,当时没有答上来!! 所以看到的小伙伴一定要注意了!! 变化浏览器宽度可看到效果: 左 右 中 然后我们来看看代码: 第一种方法:(浮动) <style type ...
- Content Providers
Content providers manage access to a structured set of data. They encapsulate the data, and provide ...
- CSS居中的方法总结
[水平居中] 行内:text-align:center; 定宽块状:1.left:0 right:0然后用margin: auto外边距填充,水平方向不会发生外边距叠加; 2.绝对定位(父元素定位不 ...
- 【BZOJ1012】【树状数组求区间最值】最大数maxnumber
Description 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度. 2. ...
- MVC埰坑日记 文件权限
public static void DownLoadFile(string FileFullPath) { if (!string.IsNullOrEmpty(FileFullPath) & ...
- __call方法简介
作用:当程序试图调用不存在或不可见的成员方法时,PHP会先调用__call方法来储方法名及参数. __call方法包含两个参数:即方法名和方法参数.其中,方法参数是以数组形式存在的.
- python 图片压缩存储
python(PIL)图像处理(等比例压缩.裁剪压缩) 缩略(水印)图 http://outofmemory.cn/code-snippet/12264/python-PIL-image-proces ...
- jquery 获取元素的 实际宽度和高度
jquery outerHeight方法 outerWidth方法 转: http://www.cnblogs.com/zhja/archive/2012/11/07/2758665.html jqu ...