动态规划(背包问题):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 ...
随机推荐
- CentOS6安装配置rsh
基本信息:节点一:ip:192.168.8.166 主机名:hadrtest01节点二:ip:192.168.8.250 主机名:hadrtest02 1.两节点分别安装rsh,rsh-server包 ...
- HDU 4296 Buildings(贪心)
题意: 给定n个建筑物,每个建筑物都有两个属性w, s,每个建筑物都有一个PDV = (Σw j)-s i .意思就是它上面的所有的w相加减去它的s,让求怎么放置这个建筑物使得每个建筑物当中PDV最大 ...
- MySQL - 复制数据表
假设现在有张数据表 users: CREATE TABLE users ( userid ) UNSIGNED NOT NULL, username ) UNIQUE, passwd ) ', PRI ...
- WCF,WebAPI,WCFREST和WebService的区别
Web ServiceIt is based on SOAP and return data in XML form.It support only HTTP protocol.It is not o ...
- [转帖]vivado & VS2013工具
来源:http://bbs.csdn.net/topics/380057699 添加OpenCV库后,MFC在Debug模式下调试,提示应用程序无法正常启动(0xc000007b). 解决方法:在环境 ...
- 使用AutoMapper实现Dto和Model之间自由转换
应用场景:一个Web应用通过前端收集用户的输入成为Dto,然后将Dto转换成领域模型并持久化到数据库中.另一方面,当用户请求数据时,我们又需要做相反的工作:将从数据库中查询出来的领域模型以相反的方式转 ...
- linux下启动oracle服务命令
以redflag(redhat /centos)linux下的 oracle 10g 为例: 如果oracle安装和配置都没有问题的话: 依次执行以下代码即可启动oracle服务. #su - ora ...
- c#与c++交互的一些东西
最近做一个项目,对方公司只提供了一个c++的DLL,但没封住,c#无法DllImport.所以只能自己写c++来封住了. 对方的Dll只接收yuv420的图片格式,所以在c++里用opencv来转换. ...
- cas的url中去掉jsessionid
Servlet3.0规范中的<tracking-mode>允许你定义JSESSIONID是存储在cookie中还是URL参数中.如果会话ID存储在URL中,那么它可能会被无意的存储 在多个 ...
- MySQL的C++简单封装
/* *介绍:MySQL的简单封装,支持流操作输入输出MySQL语句,然而并没有什么软用,大二学生自娱自乐,有不足求指点 *作者:MrEO *日期:2016.3.26 */ 头文件 my_sql.h ...