poj 2392 建塔(多重背包+不定上界)
http://blog.csdn.net/libin56842/article/details/9492351
这次比较理解那个!dp[j]是为了什么,因为是滚动数组,没有这个的话used那边会出问题
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <cctype>
#include <vector>
#include <iterator>
#include <set>
#include <map>
#include <sstream>
using namespace std; #define mem(a,b) memset(a,b,sizeof(a))
#define pf printf
#define sf scanf
#define spf sprintf
#define pb push_back
#define debug printf("!\n")
#define MAXN 1010
#define MAX(a,b) a>b?a:b
#define blank pf("\n")
#define LL long long
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
#define pqueue priority_queue
#define INF 0x3f3f3f3f struct node
{
int h,c,a;
}p[]; int K; bool dp[]; int used[]; int cmp(const node& x,const node& y)
{
return x.a<y.a;
} int main()
{
int i,j,k;
while(~sf("%d",&K))
{
for(i=;i<=K;i++)
{
sf("%d%d%d",&p[i].h,&p[i].a,&p[i].c);
} sort(p+,p+K+,cmp); /*
for(i=1;i<=K;i++)
{
pf("%d %d %d\n",p[i].h,p[i].a,p[i].c);
}*/ mem(dp,false);
dp[] = true;
int ans = ;
for(i=;i<=K;i++)
{
mem(used,);
for(j=p[i].h;j<=p[i].a;j++)
{
if(!dp[j] && dp[j-p[i].h] && used[j-p[i].h]<p[i].c)
{
dp[j] = true;
used[j] = used[j-p[i].h] + ;
//pf("%d %d %d\n",i,j,used[j]);
if(ans<j) ans = j;
}
}
}
pf("%d\n",ans);
}
return ;
}
poj 2392 建塔(多重背包+不定上界)的更多相关文章
- poj 2392 Space Elevator(多重背包+先排序)
Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...
- POJ 2392 Space Elevator(多重背包变形)
Q: 额外添加了最大高度限制, 需要根据 alt 对数据进行预处理么? A: 是的, 需要根据 alt 对数组排序 Description The cows are going to space! T ...
- poj 1742 Coins (多重背包)
http://poj.org/problem?id=1742 n个硬币,面值分别是A1...An,对应的数量分别是C1....Cn.用这些硬币组合起来能得到多少种面值不超过m的方案. 多重背包,不过这 ...
- POJ 1014 Dividing(多重背包+二进制优化)
http://poj.org/problem?id=1014 题意:6个物品,每个物品都有其价值和数量,判断是否能价值平分. 思路: 多重背包.利用二进制来转化成0-1背包求解. #include&l ...
- POJ 1276 Cash Machine(多重背包的二进制优化)
题目网址:http://poj.org/problem?id=1276 思路: 很明显是多重背包,把总金额看作是背包的容量. 刚开始是想把单个金额当做一个物品,用三层循环来 转换成01背包来做.T了… ...
- Poj 1276 Cash Machine 多重背包
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26172 Accepted: 9238 Des ...
- POJ 1014 Dividing(多重背包)
Dividing Description Marsha and Bill own a collection of marbles. They want to split the collectio ...
- poj 1276 Cash Machine_多重背包
题意:略 多重背包 #include <iostream> #include<cstring> #include<cstdio> using namespace s ...
- POJ 1472 Coins (多重背包+滚动数组)
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 25827 Accepted: 8741 Description Pe ...
随机推荐
- 解决myeclipse打开.form文件报错
症状: 打开AutoEKPMainFrm.form文件的时候出现如下问题:
- 剑指offer——面试题23:链表中环的入口节点
函数: ListNode* MeetingNode(ListNode* pHead) { if(pHead==nullptr) return nullptr; ListNode* quickNode= ...
- 用selenium工具做软件自动化测试的面试题及答案
1.selenium中如何判断元素是否存在? 答:isElementPresent 2.selenium中hidden或者是display = none的元素是否可以定位到? 答:不可以定位到 3.s ...
- Git命令之回退篇 git revert git reset
Git command之回退篇 欲练回退 必先了解:HEAD.index.WorkingCopy HEAD: 当前所在的分支版本顶端的别名,也就是最新的一次commit. git commit 之后与 ...
- Quartz .net 禁止并行触发
DisallowConcurrentExecution 禁用同步执行防止一个job 同一时间执行多次. [DisallowConcurrentExecution] public class Order ...
- 4G模块在AM335x上的移植
关于4G模块的移植 看到一个很实用的写的比较好的 借鉴一下 参考:https://e2echina.ti.com/question_answer/dsp_arm/sitara_arm/f/25/ ...
- web file
Blob 对象表示一个不可变.原始数据的类文件对象 构造函数 var aBlob = new Blob( array, options ); var aFileParts = ['<a id=& ...
- C# Stopwatch 类
命名空间:System.Diagnostics Stopwatch 实例可以测量一个时间间隔的运行时间,也可以测量多个时间间隔的总运行时间.在典型的 Stopwatch 方案中,先调用 Start 方 ...
- Delphi对话框初始地址InitialDir
我的电脑:SaveDialog1.InitialDir := '::{20D04FE0-3AEA-1069-A2D8-08002B30309D}';// My Computer {20D04FE0-3 ...
- python 冒泡和快排,不多说
#-*-coding:utf8-*- import random a=[] b=[] def init_array(): for i in range(10000): v = random.randi ...