poj 1742 Coins (动态规划,背包问题)
| Time Limit: 3000MS | Memory Limit: 30000K | |
| Total Submissions: 32977 | Accepted: 11208 |
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 题目大意:有n种面值分别为A[1],A[2],...,A[N]的硬币,硬币的个数分别为c[1],c[2],...,c[n],问这些硬币能凑出多少种m以下(包括m)的数
这是我去年比赛时遇到的第一道题,现在才明白,这是一道多重背包问题,下面是我的ac代码:
#include<iostream>
#include<string.h>
using namespace std;
int dp[],sum[];
int m,n,a[],c[];
int main(){
while(cin>>n>>m&&n+m){
for(int i=;i<=n;i++) cin>>a[i];
for(int i=;i<=n;i++) cin>>c[i];
memset(dp,,sizeof(dp));
dp[]=;
int ans=;
for(int i=;i<=n;i++){
memset(sum,,sizeof(sum));
for(int j=a[i];j<=m;j++){
if(!dp[j]&&dp[j-a[i]]&&sum[j-a[i]]<c[i]){
dp[j]=;
sum[j]=sum[j-a[i]]+;
ans++;
}
}
}
cout<<ans<<endl;
}
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: 32955 Accepted: 11199 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 ...
随机推荐
- android瀑布流效果(仿蘑菇街)
Android 转载分享(10) 我们还是来看一款示例:(蘑菇街) 看起来很像我们的gridview吧,不过又不像,因为item大小不固定的,看起来是不是别有一番风味,确实如此. ...
- Apache mod_jk
http://tomcat.apache.org/connectors-doc/generic_howto/loadbalancers.html http://tomcat.apache.org/co ...
- C# Web中Session的使用
1. 关于使用之前要注意的: 在使用session之前,一定要注意继承自System.Web.UI.Page,或在使用session时加上System.Web.HttpContext.Current: ...
- git服务器搭建-new
http://blog.chinaunix.net/uid-26729093-id-4652536.html 基本命令使用:http://www.cnblogs.com/xdao/p/linux_gi ...
- --tags --follow-tags 的区别
--tags All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the comm ...
- 关于eclipse中maven项目的问题
问题1: 严重: Error configuring application listener of class org.springframework.web.context.ContextLoad ...
- eclipse 新建 maven 项目 添加 spring hibernate 的配置文件 详情
主要配置文件 pom.xml 项目的maven 配置文件 管理项目所需 jar 依赖支持 web.xml 项目的总 配置文件 :添加 spring和hibernate 支持 applicationC ...
- dx中纹理相关的接口备注
1.内存中的纹理保存到文件 HRESULT D3DXSaveTextureToFile( __in LPCTSTR pDestFile, __in D3DXIMAGE_FILEFORMAT DestF ...
- js 中 continue 与 break 熟练使用
//break:在循环体中,遇到break,整个循环都结束了,后面的累加操作也不在执行了,并且循环体中,只要遇到break,那么循环体break后面的代码都不在执行了 //continue:在循环体中 ...
- 20145218 《Java程序设计》课程总结
20145218 <Java程序设计>课程总结 每周读书笔记链接汇总 20145218<Java程序设计>第一周学习总结 20145218<Java程序设计>第二周 ...