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. 【iScroll源码学习04】分离IScroll核心

    前言 最近几天我们前前后后基本将iScroll源码学的七七八八了,文章中未涉及的各位就要自己去看了 1. [iScroll源码学习03]iScroll事件机制与滚动条的实现 2. [iScroll源码 ...

  2. Spring(3)—— Junit框架单元测试

    Junit主要用于单元测试,即白盒测试.它是一个开源的由JAVA开发的一个用于测试的框架. Junit的几个基本概念:TestCase,TestSuite,TestFixtrue TestCase:代 ...

  3. javascript 对象初探(二)--- 返回对象的函数

    除了使用new操作符调用构造函数以外,我们也可以抛开new操作符,只用一般函数来创建对象,这样就能执行某些预备工作,并已对象为返回值的函数.. function her(){ return { nam ...

  4. 升级tomcat7的运行日志框架到log4j2,可以打进kafka

    为了让web application能随意使用logging组件而不受web容器自身的影响,从tomcat 6.0开始,tomact默认使用的是java.util.logging framework来 ...

  5. .net 模拟登录Post提交

    最近在做一个项目,要求集成到第三方系统中,由于先前没有做过类似的活,所以折腾了几天,蹭着有闲情的时候记录一下. 以下实例,都是我用Asp.net语言进行开发的,关于HTML元素的获取,使用的是Goog ...

  6. 什么是REST?

    云计算的时代越来越多的提到一个词REST,那么什么是REST?如果你还不清楚,可以看这个视频和系列教程: http://www.restapitutorial.com/lessons/whatisre ...

  7. Creating Custom Connector Sending Claims with SharePoint 2013

    from:http://blogs.msdn.com/b/security_trimming_in_sharepoint_2013/archive/2012/10/29/creating-custom ...

  8. umeng 渠道统计 android

    1.配置AndroidManifest.xml,添加权限 <uses-permission android:name="android.permission.ACCESS_NETWOR ...

  9. AVAudioSession初探

    根据文档,AudioSession规定了app和系统音频行为交互的规范,一个app只有一个AudioSession的单例. app通过设置自己AudioSession的单例的属性来告诉系统自身想达到的 ...

  10. 开发https应用

    开发https应用 SSL, 或者Secure Socket Layer,是一种允许web浏览器和web服务器通过一个安全的连接进行交流的技术.这意味着将被发送的数据在一端被翻译成密码,传送出去,然后 ...