poj 1726
http://poj.org/problem?id=1276
解题要点:用完全背包来模拟的解题,只不过加了限制条件used[]。。。其他的就一样了。。
注意: cash 和n 为0 的情况
#include <iostream>
#include<cstring>
using namespace std;
int cash,n;
int amount[],w[];
int f[];
int used[];
int maxm(){
if(cash==||n==){
return ;
}
for(int i=;i<=n;i++){
memset(used,,sizeof(used));
for(int j=w[i];j<=cash;j++){
if((f[j]<f[j-w[i]]+w[i])&&(used[j-w[i]]+<=amount[i])){
f[j] = f[j-w[i]]+w[i];
used[j] = used[j-w[i]]+;
}
}
}
return f[cash];
}
int main()
{
while(cin>>cash>>n){
for(int i=;i<=n;i++)
cin>>amount[i]>>w[i];
memset(f,,sizeof(f));
cout<<maxm()<<endl;
}
return ;
}
poj 1726的更多相关文章
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- poj 动态规划题目列表及总结
此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...
- poj动态规划列表
[1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- POJ 动态规划题目列表
]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...
- poj 动态规划的主题列表和总结
此文转载别人,希望自己可以做完这些题目. 1.POJ动态规划题目列表 easy:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, ...
- 转载:poj题目分类(侵删)
转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) ...
- poj和hdu部分基础算法分类及难度排序
最近想从头开始刷点基础些的题,正好有个网站有关于各大oj的题目分类(http://www.pythontip.com/acm/problemCategory),所以写了点脚本把hdu和poj的一些题目 ...
随机推荐
- ash, bash, ksh, csh, zsh
/bin/bash (就是 Linux 预设的 shell, 是现在很多Linux的发行版中默认的shell,综合了其他shell的很多优点.)/bin/ksh (Kornshell 由 AT& ...
- Euromonitor 2013年奢侈品报告精选 |华丽志
Euromonitor 2013年奢侈品报告精选 |华丽志 Euromonitor 2013年奢侈品报告精选
- (92) Is there a better crawler than Scrapy? - Quora
(92) Is there a better crawler than Scrapy? - Quora Is there a better crawler than Scrapy?Edit
- hdu 1507 Largest Rectangle in a Histogram 动态规划计算最大面积
记录动态规划dpl,dpr,分辨记录i左面的比i大的,右面比i大的,然后(dpr[i]-dpl[i]+1)*h[i]得出长度 动态转移方程while(temp>1 && h[te ...
- The Building Blocks-Components of EA part 1- Information and Strategy
1. Zachman Framework Presented as matrix of Rows and Columns representing domain of interest and lev ...
- 本地yum源安装GCC
Linux环境下yum源安装GCC 前提条件是有Linux环境的安装盘ISO文件 在Linux系统中创建两个目录,一个是用来存放ISO文件,一个是用来挂载该ISO文件,如下: $mkdir /root ...
- HTTP有关知识
Cookie 调用Cookie时,由于可校验Cookie的有效期,以及发送方的域,路径,协议等信息,所以正规发布的Cookie里面的内容不会因来自其他web站点和攻击者的攻击而泄露. Set-Cook ...
- video标签 拖动 转自w3school
调整视频大小 播放 暂停 用js实现 详细参见http://www.w3school.com.cn/tiy/t.asp?f=html5_video_dom 图片的拖动详见http://www.w3sc ...
- TabelView的多选模式
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource> @property(nonatomic,st ...
- Android 开发笔记“调用.net webservice遇到的问题”
1.An exception occurred: org.ksoap2.SoapFault SoapFault - faultcode: 'soap:Server' faultstring: '服务器 ...