Coins
Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 32977   Accepted: 11208

Description

People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar.One day Tony opened his money-box and found there were some coins.He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact price(without change) and he known the price would not more than m.But he didn't know the exact price of the watch.
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

The
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

For each test case output the answer on a single line.

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 (动态规划,背包问题)的更多相关文章

  1. hdu 2844 poj 1742 Coins

    hdu 2844 poj 1742 Coins 题目相同,但是时限不同,原本上面的多重背包我初始化为0,f[0] = 1;用位或进行优化,f[i]=1表示可以兑成i,0表示不能. 在poj上运行时间正 ...

  2. 题解报告:hdu 2844 & poj 1742 Coins(多重部分和问题)

    Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. On ...

  3. [POJ 1742] Coins 【DP】

    题目链接:POJ - 1742 题目大意 现有 n 种不同的硬币,每种的面值为 Vi ,数量为 Ni ,问使用这些硬币共能凑出 [1,m] 范围内的多少种面值. 题目分析 使用一种 O(nm) 的 D ...

  4. 动态规划(背包问题):POJ 1742 Coins

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 32955   Accepted: 11199 Descripti ...

  5. poj 1742 Coins(dp之多重背包+多次优化)

    Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...

  6. POJ 1742 Coins(多重背包, 单调队列)

    Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...

  7. Poj 1742 Coins(多重背包)

    一.Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dolla ...

  8. poj 1742 Coins (多重背包)

    http://poj.org/problem?id=1742 n个硬币,面值分别是A1...An,对应的数量分别是C1....Cn.用这些硬币组合起来能得到多少种面值不超过m的方案. 多重背包,不过这 ...

  9. POJ 1742 Coins (多重背包)

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 28448   Accepted: 9645 Descriptio ...

随机推荐

  1. iOS之Photos:访问某个相册通过collectionView显示

    文中相关知识点较多,只记载重点思路,相关部分都有对应注释说明,部分还需要优化,只是工作学习的一种思路. @import AVFoundation; @import Photos;   导入框架 - ( ...

  2. JAVA 程序设置运行内存

    1.修改jdk设置 2.如果不行则 一般安装完eclipse之后,在安装目录下你应该可以看到有一个 eclipse.ini 文件,对了,就是在这个文件里面修改 -vmargs:说明后面是VM的参数 - ...

  3. OpenGL的几何变换4之内观察全景图

    上一次写了OpenGL的几何变换3之内观察全景图 上次采用的是图片分割化方式,这次采用数据分割化方式. 先说下思路,数据分割化方式呢,是只读取一张图片imgData,然后通过glTexCoord2f( ...

  4. android下调用C,JNI调用

    1.eclipse中声明调用的C函数  com.example.test.MainActivity public native long RucMyfunction(int w,int h,int[] ...

  5. iOS开发 字符串MD5加密

    /*** MD5 ***/ #define CC_MD5_DIGEST_LENGTH    16          /* digest length in bytes */ #define CC_MD ...

  6. phprpc 使用实例(例实没错却不能执行)函数冲突gzdecode

    PHPRPC 是一个轻型的.安全的.跨网际的.跨语言的.跨平台的.跨环境的.跨域的.支持复杂对象传输的.支持引用参数传递的.支持内容输出重定向的.支持分级错误处理的.支持会话的.面向服务的高性能远程过 ...

  7. AHCI驱动安装

    目录 第1章 Windows XP    1 1.1 更新驱动    1 第2章 Windows 7    7 2.1 修改注册表    7 2.2 更新驱动    7 第1章 Windows XP ...

  8. C#综合揭秘——细说多线程(上)

    引言 本文主要从线程的基础用法,CLR线程池当中工作者线程与I/O线程的开发,并行操作PLINQ等多个方面介绍多线程的开发. 其中委托的BeginInvoke方法以及回调函数最为常用. 而 I/O线程 ...

  9. (27)odoo 中改变菜单动作的默认视图

    一个动作下面有多个视图来支持,像表单视图.列表视图.看板视图.图表视图等 这时我们想改变系统默认指定的视图,方法其实有两种,一种是通过面板改,一种是开发一个小模块 举一例:项目默认打开是用了看板视图, ...

  10. 补第二周四人小组WBS/NABCD

    四人小组项目<东北师范大学论坛> 要求: 1.给出需求概述.功能列表.痛点或亮点.NABCD及WBS模型在此项目中的应用. 2.不熟悉的名词,自行搜索资料并参考教材第393页开始的术语索引 ...