Coins
Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 34814   Accepted: 11828

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

Source

---------------------------
Orz楼爷
多重背包可行性,用O(NV)做法
滚动数组掉N那一维,否则MLE
#include<iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=,V=1e5+;
int n,m,f[V],c[N],v[N],ans=; void mpAble(){
memset(f,-,sizeof(f));
f[]=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(f[j]>=) f[j]=c[i];
else f[j]=-;
}
for(int j=;j<=m-v[i];j++)
if(f[j]>=)
f[j+v[i]]=max(f[j+v[i]],f[j]-);
}
}
int main(int argc, const char * argv[]) {
while(cin>>n>>m){
if(n==&&m==) break;
for(int i=;i<=n;i++) scanf("%d",&v[i]);
for(int i=;i<=n;i++) scanf("%d",&c[i]);
mpAble();
for(int i=m;i>=;i--)if(f[i]>=) ans++;
cout<<ans<<"\n";ans=; }
return ;
}

POJ1742 Coins[多重背包可行性]的更多相关文章

  1. $POJ1742\ Coins$ 多重背包+贪心

    Vjudge传送门 $Sol$ 首先发现这是一个多重背包,所以可以用多重背包的一般解法(直接拆分法,二进制拆分法...) 但事实是会TLE,只能另寻出路 本题仅关注“可行性”(面值能否拼成)而不是“最 ...

  2. POJ1742:Coins(多重背包)

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

  3. poj1742硬币——多重背包可行性

    题目:http://poj.org/problem?id=1742 贪心地想,1.如果一种面值已经可以被组成,则不再对它更新: 2.对于同一种面值的硬币,尽量用较少硬币(一个)更新,使后面可以用更多此 ...

  4. POJ1276Cash Machine[多重背包可行性]

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 32971   Accepted: 11950 De ...

  5. POJ 3260 The Fewest Coins(多重背包+全然背包)

    POJ 3260 The Fewest Coins(多重背包+全然背包) http://poj.org/problem?id=3260 题意: John要去买价值为m的商品. 如今的货币系统有n种货币 ...

  6. HDU-2844 Coins(多重背包)

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

  7. POJ3260——The Fewest Coins(多重背包+完全背包)

    The Fewest Coins DescriptionFarmer John has gone to town to buy some farm supplies. Being a very eff ...

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

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

  9. HDU2844 Coins 多重背包

    Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

随机推荐

  1. babel 无法解析jsx (webpack react )

    webpack.config.js的配置如下图: 报错: 修改webpack.config.js文件,如下即可:

  2. 原生JS:String对象详解

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  3. spring web MVC

    详情:http://blog.csdn.net/mic_hero/article/details/50237627

  4. ArcGIS中的WKID

    提到坐标系统,大家多少能明白一些,但在运用时,有些朋友搞得不是非常清楚,以后专门来总结.在实地生产项目中,使用较多的2000中国大地坐标系(CGCS2000).1980西安坐标系.1954北京坐标系统 ...

  5. CALayer 易混淆的两个属性 - position和anchorPoint

    1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property CGPoint position;                           ...

  6. CAShaperLayer的应用

    关于CAShapeLayer的一些实用案例和技巧 实现遮罩 音量大小动态改变的控件 圆形进度条 iOS 利用CAShapeLayer的FillRule属性生成一个空心遮罩的layer fillrule ...

  7. sqlite API模型

     每一个数据库连接可以包括多个数据库文件,一个主数据库文件和attached的几个数据库文件. 每一个数据库文件都有自己的B-tree和pager. 数据库连接(connection)和事务(tra ...

  8. iOS--页面跳转(UITableView)

    本文只要实现运用(UITableView)表格实现页面的传值,同时运用了代理(委托)传值. 目录文件列表如下: AddressBookViewController.h #import <UIKi ...

  9. 在SQL2008中使用XML应对不确定结构的参数

    目的:统一接口,当数据结构发生变化时,前后端业务接口不发生变化,由业务具体解析结构. 规则:确定的接口用参数表(多行提交),不确定的参数用XML   DECLARE @r TABLE     (    ...

  10. 自定义可视化调试工具(Microsoft.VisualStudio.DebuggerVisualizers)vs.net开发工具

    背景: 话说:使用CYQ.Data时,会经常断点MDataTable的对象,为了查看表格的数据内容,在监视里会常ToDataTable(),然后借可DataTable的可视化方式查看表格. 近日:心中 ...