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 建塔(多重背包+不定上界)的更多相关文章

  1. poj 2392 Space Elevator(多重背包+先排序)

    Description The cows are going to space! They plan to achieve orbit by building a sort of space elev ...

  2. POJ 2392 Space Elevator(多重背包变形)

    Q: 额外添加了最大高度限制, 需要根据 alt 对数据进行预处理么? A: 是的, 需要根据 alt 对数组排序 Description The cows are going to space! T ...

  3. poj 1742 Coins (多重背包)

    http://poj.org/problem?id=1742 n个硬币,面值分别是A1...An,对应的数量分别是C1....Cn.用这些硬币组合起来能得到多少种面值不超过m的方案. 多重背包,不过这 ...

  4. POJ 1014 Dividing(多重背包+二进制优化)

    http://poj.org/problem?id=1014 题意:6个物品,每个物品都有其价值和数量,判断是否能价值平分. 思路: 多重背包.利用二进制来转化成0-1背包求解. #include&l ...

  5. POJ 1276 Cash Machine(多重背包的二进制优化)

    题目网址:http://poj.org/problem?id=1276 思路: 很明显是多重背包,把总金额看作是背包的容量. 刚开始是想把单个金额当做一个物品,用三层循环来 转换成01背包来做.T了… ...

  6. Poj 1276 Cash Machine 多重背包

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26172   Accepted: 9238 Des ...

  7. POJ 1014 Dividing(多重背包)

    Dividing   Description Marsha and Bill own a collection of marbles. They want to split the collectio ...

  8. poj 1276 Cash Machine_多重背包

    题意:略 多重背包 #include <iostream> #include<cstring> #include<cstdio> using namespace s ...

  9. POJ 1472 Coins (多重背包+滚动数组)

    Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 25827 Accepted: 8741 Description Pe ...

随机推荐

  1. jquery源码解析:代码结构分析

    本系列是针对jquery2.0.3版本进行的讲解.此版本不支持IE8及以下版本. (function(){ (21, 94)     定义了一些变量和函数,   jQuery = function() ...

  2. Archlinux 下系统如何设置让 Wine 调用 ibus输入法

    前言: 如果你是fcitx输入法用户,那么这篇文章大可不必看.fcitx是一个非常强大的框架,著名搜狗输入法就是基于fcitx输入法架构开发的.据我所知.您遇到这个问题可以通过卸载ibus输入法进行修 ...

  3. To 高一

    Linux 坑待填 Special Judge 什么是 Special Judge?有的题目会让你输出任意一个解即可AC,或者是让你输出部分答案能取得本测试点部分得分,或者是按照方案的优秀程度给你分, ...

  4. 条目二十四《当效率至关重要时,请在map::operator[]与map::insert之间谨慎做出选择》

    条目二十四<当效率至关重要时,请在map::operator[]与map::insert之间谨慎做出选择> 当效率至关重要时,应该在map::operator[]和map::insert之 ...

  5. 牛客 Wannafly挑战赛27 D 绿魔法师

    传送门 \(\color{green}{solution}\) 分析下,在\(1e5+1\)内,一个数的约数个数最多为\(2^{6}\)个,所以我们可以考虑枚举约数 复杂度\(O(N^{2^{6 \t ...

  6. 【算法笔记】B1045 快速排序

    1045 快速排序 (25 分)   著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边. 给定划分后 ...

  7. MySQL使用UNIQUE实现数据不重复插入

    unique列在一个UNIQUE键上插入包含重复值的记录时,我们可以控制MySQL如何处理这种情况:使用IGNORE关键字或者ON DUPLICATE KEY UPDATE子句跳过INSERT.中断操 ...

  8. ORACLE INSERT ALL 用法

    1INSERT ALL 1.1句法 multi_table_insert :: = conditional_insert_clause :: = 1.2multi_table_insert 在多表插入 ...

  9. spark第九篇:Spark操作ES

    spark操作es需要elasticsearch-hadoop-xxx.jar,版本需同es版本.从5.0版本开始,支持spark2.0. 把elasticsearch-hadoop-xxx.jar放 ...

  10. 如何使一个div能够铺满整个页面? && 模态框的制作 && outerHTML

    说明: 使用 ele.outerHTML = '' 这样的方法可以很容易的清除一个元素. 当然也可以使用parent.removeChild() ,但是相较而言,还是使用 outerHTML = '' ...