POJ 1742 Coins
来源:互联网 发布:大学网络诋毁严正声明 编辑:程序博客网 时间:2024/06/06 11:17
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.
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 101 2 4 2 1 12 51 4 2 10 0
Sample Output
84
Source
LouTiancheng@POJ
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
“男人八题”第六道~
但其实就是裸的多重背包吧,类似dfs?
神奇的记录方法本蒟蒻还是第一次见……太神了!
#include<cstdio>#include<cstring> int n,m,a[105],c[105],f[100005],now[100005],tot;int main(){ while(scanf("%d%d",&n,&m) && n){memset(f,0,sizeof(f)); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) scanf("%d",&c[i]); tot=0;f[0]=1; for(int i=1;i<=n;i++){ memset(now,0,sizeof(now)); for(int j=a[i];j<=m;j++) if(!f[j] && f[j-a[i]] && now[j-a[i]]+1<=c[i]) { f[j]=1; now[j]=now[j-a[i]]+1; tot++; } } printf("%d\n",tot); } return 0;}
1 0
- poj 1742 Coins
- POJ 1742 Coins
- POJ 1742 Coins
- poj 1742 Coins
- poj 1742 Coins
- POJ 1742 coins
- POJ 1742 Coins
- poj 1742 Coins
- POJ 1742 Coins
- poj 1742 coins
- POJ 1742 Coins (DP)
- poj 1742 Coins
- poj 1742 Coins(dp)
- POJ 1742 Coins
- poj 1742 Coins
- 【POJ 1742】Coins
- poj 1742 Coins
- POJ 1742 Coins
- Android ViewPager嵌套GridView实现滚动菜单(demo)
- Java 中使用 MySql以及一些Mysql 基本的命令
- Validation表单验证插件
- 深入浅出Dubbo(二)
- JavaWeb: 报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
- POJ 1742 Coins
- LeetCode | Rotate List
- python开发简单爬虫:准备篇
- 深入浅出Dubbo(三)
- 跟风式、炒作式、跨业式三类创业者最容易挂掉
- Android实现跑马灯效果
- 51nod 1279 扔盘子
- 深入浅出Dubbo(四)
- 实现memcpy( )和memmove( )函数