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. Fatal error compiling: 无效的目标发行版: 1.8 -> [Help 1] (zhuan)

    http://blog.csdn.net/z18137017273/article/details/53033613 ***************************************** ...

  2. MYSQL 【汇总数据】 【分组数据】 学习记录

    分组数据 1,创建分组:

  3. djangoadmin导出csv

    from django.contrib import admin from .models import Order,OrderItem from django.http import HttpRes ...

  4. ResponseUtil反射制造唯一结果

    调用:通过反射调用同一个类型的返回值 return fillResponse(response,Constants.SUCCESS,"获取数据成功","taskList& ...

  5. phalcon: tasks MainTask.php命令行工具

    phalcon: tasks MainTask.php命令行工具 tasks MainTask.php 一般用来做计划任务,处理比较复杂的大型的数据.然后其他功能或程序才能更简单的读取这些复杂的数据. ...

  6. java 多线程1

    进程: 线程: 多线程: 假象:只是CPU在做快速的切换 多线程的好处: 1.解决了一个进程里面可以同时运行多个任务(执行路径) 2.提高资源利用率,而不是效率. 多线程的弊端: 1.降低了一个进程里 ...

  7. @font-face字体文件用法

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. robotframework笔记14

    创建用户关键字 关键字表是用于创建新的更高层次的关键词 结合现有的关键词. 这些关键字被称为 用户 关键字 区分他们的最低水平 库关键字 实现在测试库. 的语法创建用户 关键词非常接近的语法创建测试用 ...

  9. 【转】commons-lang.jar包简介

    转自:http://zhidao.baidu.com/share/71b48e6b3e1b1dc73fe705604b9c7584.html 1.下载jar包 包官方下载地址:http://commo ...

  10. [maven] 使用问题及思考汇总

    (1)Maven坐标 maven坐标可以唯一标识一个项目,包含四个元素 groupId , artifactId, packaging, version. groupId:一般为团体,公司,项目.如 ...