poj Cash Machine
http://poj.org/problem?id=1276
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define For(n) for(int i=1; i<=(n); i++)
#define maxn 100010
using namespace std; int dp[maxn];
struct node
{
int n;
int m;
}p[maxn];
int cash,n; int main()
{
while(scanf("%d%d",&cash,&n)!=EOF)
{
For(n) scanf("%d%d",&p[i].n,&p[i].m);
if(n==||cash==) {printf("0\n");continue;}
int max1=;
memset(dp,,sizeof(dp));
dp[]=;
for(int i=; i<=n; i++)
{
for(int j=max1; j>=; j--)
{
if(dp[j])
{
for(int k=; k<=p[i].n; k++)
{
int sum=j+k*p[i].m;
if(sum>cash) break;
dp[sum]=;
max1=max(max1,sum);
}
}
}
}
printf("%d\n",max1);
}
return ;
}
poj Cash Machine的更多相关文章
- Poj 1276 Cash Machine 多重背包
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26172 Accepted: 9238 Des ...
- poj 1276 Cash Machine(多重背包)
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33444 Accepted: 12106 De ...
- POJ 1276 Cash Machine
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24213 Accepted: 8476 Descrip ...
- POJ 1276 Cash Machine(单调队列优化多重背包)
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 38986 Accepted: 14186 De ...
- POJ 1276:Cash Machine 多重背包
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30006 Accepted: 10811 De ...
- POJ 1276 Cash Machine(多重背包)
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24132 Accepted: 8446 Descrip ...
- PKU 1276 Cash Machine
<span style="color:#000099;">/* Cash Machine Time Limit: 1000MS Memory Limit: 10000K ...
- Cash Machine(多重背包二进制转换)
个人心得:多重背包,自己根据转换方程写总是TLE,后面去网上看了二进制转换,不太理解: 后面仔细想了下,用自己的思想理解下把,就是将对应number,cash总和用二进制拆分, 然后全部装入到一个数组 ...
- POJ 1276 Cash Machine -- 动态规划(背包问题)
题目地址:http://poj.org/problem?id=1276 Description A Bank plans to install a machine for cash withdrawa ...
随机推荐
- [Angular 2] The form export from NgFormControl
In last post, we need to create an instanse variable: sku: AbstructControl; We can get rid of this b ...
- PHP CodeBase: 判断用户是否手机访问(转)
随着移动设备的普及,网站也会迎来越来越多移动设备的访问.用适应PC的页面,很多时候对手机用户不友好,那么有些时候,我们需要判断用户是否用手机访问,如果是手机的话,就跳转到指定的手机友好页面.这里就介绍 ...
- LVS图解 ---阿里
LVS在大规模网络环境中的应用 1. SLB总体架构 LVS本身是开源的,我们对它进行了多方面的改进,并且也已开源-https://github.com/alibaba/LVS. 接下 ...
- java.util.jar.JarFile cause native heap memory leak
最近项目中使用了JarFile 这个类 来load jar包中的 configuration,大致的情况如下 public void processJarEntries(JarFile paramJa ...
- 体验Impress.js
用腻了ppt,prezi的风格看起来更酷一点儿,无意中得知有Impress.js这么一个H5版的prezi,nice,值得一试. 关于Impress.js,网上教程很多,但说实话就跟教小朋友一样,一步 ...
- iOS网络HTTP、TCP、UDP、Socket 知识总结
OSI 七层模型 我们一般使用的网络数据传输由下而上共有七层,分别为物理层.数据链路层.网络层.传输层.会话层.表示层.应用层,也被依次称为 OSI 第一层.第二层.⋯⋯. 第七层. 如下图: 各层功 ...
- Bellman_ford POJ 3259 Wormholes
Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 41728 Accepted: 15325 Descr ...
- 【开源java游戏框架libgdx专题】-01-libgdx介绍
libgdx是一款开源的java游戏框架,而且还实现了Desktop/Android/BlackBerry/iOS/HTML5这些些平台的跨平台开发.官方网址:https://libgdx.badlo ...
- css样式之背景图片
1.css样式背景之使用图片来做为背景 example: <!DOCTYPE html> <html> <head> <meta http-equiv=&qu ...
- contains选择器
有这样一个问题: 一个列表里面,很多option,但是在不知道value,只知道他的内容的时候,怎么进行选择,比如: 北京市天津市上海市重庆市 在不知道他的value和index的时候,选择北京市,能 ...