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. 转:union 联合体(共用体)

    转自:http://blog.csdn.net/xiao3404/article/details/22276485 2.共用体 2.1共用体的概念 共用体是一种构造类型的数据结构.在一个“共用体”内可 ...

  2. 有关使用Maven常见问题总结(Eclipse中使用Maven、Maven项目部署到tomcat等问题)

    http://blog.csdn.net/sunitjy/article/details/42709311 ********************************************** ...

  3. Sqoop安装配置及数据导入导出

    前置条件 已经成功安装配置Hadoop和Mysql数据库服务器,如果将数据导入或从Hbase导出,还应该已经成功安装配置Hbase. 下载sqoop和Mysql的JDBC驱动 sqoop-1.2.0- ...

  4. noip2016酱油记day1

    真的是noip2016酱油记了. t1模拟,应该可以过. t2用了个简单的桶瞎搞,估计剩50pt了. t3直接不会写. 心好累... 考的分数肯定没去年高. 但不论如何,明天正常发挥就好. 正常发挥下 ...

  5. IIS提示Server Application Unavailable

    浏览器访问网站,IIS提示Server Application Unavailable,我的解决方式是进入IIS管理界面,找到对应的站点,之后重启这个站点.

  6. [saiku] 通过 saiku 的 DEMO 分析 connection

    示例:FOODMART connection: foodmart catalog: FoodMart schema: FoodMart cube: Sales/HR/Sales 2/.../ ==== ...

  7. MyEclipse自动补全与快捷键设置

    一般默认情况下,Eclipse ,MyEclipse的代码提示功能是比Microsoft Visual Studio的差很多的,主要是Eclipse ,MyEclipse本身有很多选项是默认关闭的,要 ...

  8. js为元素添加onclick事件

    $("div.manu a:last").on('click',function(){ if (page == totalPage) { return; } page = page ...

  9. [转]RAID技术介绍和总结

    以下内容转自伯乐在线:http://blog.jobbole.com/83808/ 原文出处: 涯余(@若东临于沧海) ---------------------------------------- ...

  10. PDF 补丁丁 0.4.2.891 测试版发布:合并PDF文件时设置书签文本和样式

    新的测试版在合并文件界面增加了设置书签样式的功能.除了可以为所合并的图片(或PDF文件)指定书签文本之外,还可以指定其文本样式(文本颜色.粗体.斜体).如下图所示. 此外,合并文件界面还添加了文件夹历 ...