Coins [POJ1742] [DP]
Input
(n<=100,m<=100000,面额<=100000,每种个数<=1000)
Output
Sample Input
3 10
1 2 4 2 1 1
2 5
1 4 2 1
0 0
Sample Output
8
4
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define RG register int
#define rep(i,a,b) for(RG i=a;i<=b;++i)
#define per(i,a,b) for(RG i=a;i>=b;--i)
#define ll long long
#define inf (1<<29)
#define maxn 105
#define maxm 100005
using namespace std;
int n,m;
int val[maxn],num[maxn];
int dp[maxm];
inline int read()
{
int x=,f=;char c=getchar();
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} void DP()
{
memset(dp,-,sizeof(dp));
dp[]=;
rep(i,,n)
rep(j,,m)
{
if(dp[j]>=) dp[j]=num[i];
else if(val[i]>j||dp[j-val[i]]<=) dp[j]=-;
else dp[j]=dp[j-val[i]]-;
}
int ans=;
rep(i,,m)
if(dp[i]>=) ans++;
printf("%d\n",ans);
} int main()
{
while()
{
n=read(),m=read();
if(!n&&!m) return ;
rep(i,,n) val[i]=read();
rep(i,,n) num[i]=read();
DP();
}
return ;
}
Coins [POJ1742] [DP]的更多相关文章
- PAT甲题题解-1068. Find More Coins (30)-dp,01背包
一开始没多想,虽然注意到数据N<=10^4的范围,想PAT的应该不会超时吧,就理所当然地用dfs做了,结果最后一组真的超时了.剪枝啥的还是过不了,就意识到肯定不是用dfs做了.直到看到别人说用0 ...
- hdu 1398 Square Coins(简单dp)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Pro ...
- poj 1742 Coins(dp之多重背包+多次优化)
Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...
- SGU 415. Necessary Coins ( 背包dp )
题意大概是:给出N个硬币, 面值为a_i, 问要凑成X元哪些硬币是不可或缺的.1 ≤ N ≤ 200, 1 ≤ x ≤ 10^4 直接枚举, 然后就是01背包了. 为了不让复杂度多乘个N, 我们就从左 ...
- atcoderI - Coins ( 概率DP)
I - Coins Time Limit: 2 sec / Memory Limit: 1024 MB Score : 100100 points Problem Statement Let NN b ...
- 【CF944G】Coins Exhibition DP+队列
[CF944G]Coins Exhibition 题意:Jack去年参加了一个珍稀硬币的展览会.Jack记得一共有 $k$ 枚硬币,这些硬币排成一行,从左到右标号为 $1$ 到 $k$ ,每枚硬币是正 ...
- ACM-ICPC 2017 Asia Urumqi:A. Coins(DP) 组合数学
Alice and Bob are playing a simple game. They line up a row of nn identical coins, all with the head ...
- 2017 ICPC乌鲁木齐 A Coins 概率dp
Coins 题意:一开始所有n个硬币都是反面朝上的,每次必须拿k个来抛,抛的人足够聪明,问m次之后向上的硬币的期望. 首先说了这个足够聪明的意思,就是只要向反面的有k个就不会sb地去拿向正面的来抛,想 ...
- Coins —— POJ-1742
Time limit 3000 ms Memory limit 30000 kB Description People in Silverland use coins.They have coins ...
随机推荐
- HTTP 599: SSL certificate problem: unable to get local issuer certificate错误
自己在用 PySpider 框架爬虫运行代码后时出现 HTTP 599: SSL certificate problem: unable to get local issuer certificate ...
- python——mysql京东数据库设计案例(源码)
# 显示界面信息# 循环界面信息# 根据用户输入数据来做相应的选择from pymysql import connect def jingdong_info(): '''#显示界面信息''' prin ...
- C#通讯录——Windows Form Contact List
C#通讯录 Windows Form Contact List 主窗口 using System; using System.Collections.Generic; using System.Com ...
- 函数wait和waitpid
函数wait 一个进程在终止时会关闭所有文件描述符,释放在用户空间释放的内存,但它的PCB还保留着,内核在其中保存一些信息:如果是正常终止时则保存着退出状态,如果是异常终止则保存着导致该进程终止的信号 ...
- java.lang.OutOfMemoryError: unable to create new native thread
ps -o nlwp 70753 sudo -u tomcat jmap -dump:format=b,file=fundmarketmanage.hprof 78894
- [转] 三种方法实现js跨域访问
1.基于iframe实现跨域 基于iframe实现的跨域要求两个域具有aa.xx.com,bb.xx.com这种特点,也就是两个页面必须属于一个基础域(例如都是xxx.com,或是xxx.com.cn ...
- python全栈开发day80--评论楼、评论树
内容总结: 1. 内容回顾 1. 内容回顾 1.评论 1. 展示评论 1. 评论楼(Django模板语言渲染) 1. 从后端查询出所有的评论 2. 如果有父评论就展示父评论 2. 评论树 通过ajax ...
- net core体系-web应用程序-4net core2.0大白话带你入门-3asp.net core项目架构和配置文件解读
asp.net core web项目目录解读 Connected Services 和传统.net web项目相比,它的功能类似于添加webservice或者wcf service的引用.暂时用不 ...
- 修改input 的 placeholder
input::-webkit-input-placeholder, textarea::-webkit-input-placeholder { color: #666!important; } inp ...
- ThinkPHP页面跳转success与error方法
首先是控制器中,可以使用下代码: config配置如下: 'TMPL_ACTION_ERROR' => 'Public:error', // 默认错误跳转对应的模板文件 'TMPL_ACTION ...