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 ...
随机推荐
- phalcon: 表单
以实例为说明: controller <?php use \Phalcon\Forms\Form; use \Phalcon\Forms\Element\Text; use \Phalcon\F ...
- parent relation column can't be updated LESSON_EXTENDED_ATTRIBUTE->LESSON_ID
MyCat 中 作为分片的主键不允许更新 , 需要设置为null,调用updateSelectiveByPrimaryKey来更新数据 parent relation column can't be ...
- selenium 加载RemoteDriver浏览器驱动
title NodeWebDriver java -jar selenium-server-standalone-2.42.2.jar -Dwebdriver.ie.driver="C:\S ...
- Unity3D在Windows的全屏和跨屏(双屏)方案
方案1 unity中2个摄像机场景显示在两个显示器屏幕上(一个窗口跨屏) 1.设置场景中的两个摄像机 摄像机1 摄像机2 2.设置发布的平台及分辨率 3.全屏运行游戏,没有标题栏还可以通过-popup ...
- jQuery clone()方法绑定事件
先看如下代码: (function ($) { var div = $("<div></div>").css({width: "100px&quo ...
- Django开发博客- 部署
安装Git Git是一个被大量程序员使用的”版本控制系统”.此软件可以跟踪任何时间文件的改变,这样你以后可以随时召回某个特定版本. windows系统下面可以下载git-scm安装.除了第5步”Adj ...
- NodeJS 各websocket框架性能分析
For a current project at WhoScored, I needed to learn JavaScript, Node.js and WebSocket channel, aft ...
- nodeschool.io 4
~~ MY FIRST ASYNC I/O! ~~ Write a program that uses a single asynchronous filesystem operationto rea ...
- 笔记13:File 类的一些操作
一.对文件的创建(create) private void button1_Click(object sender, EventArgs e) { File.Create(@"F:\\QQP ...
- HDU----(4519)郑厂长系列故事——体检
郑厂长系列故事——体检 Time Limit: 500/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total S ...