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. protobuf高效传输对比json gizp等等

    https://blog.csdn.net/u013929284/article/details/72582215 利用Protocol Buffers可以很好的解决JSON数据在传输方面的不足,它是 ...

  2. PHP用curl远程下载图片

    function http_get_data($url){ $ch = curl_init (); curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'GET' ); ...

  3. 简述Dubbo

    目前处于实习期间,白天工作,网上自主学习.最近没事逛了一下当前招聘网上的招聘要求,其中dubbo这个关键字出现的比较多,因此花了点时间学习了一番,在这写写自己的理解. 说起Dubbo,得先聊聊RPC, ...

  4. nodemon详解

    1.介绍 Nodemon是一个使用工具,它将会见监视源文件中任何的更改并自动重启服务器.Nodemon不会对你的代码产生额外的更改,它只是node命令的替代品.因为当你修改源文件后,如果你用的是原来的 ...

  5. [BZOJ 4921][Lydsy1706月赛]互质序列

    传送门 因为区间 gcd 的变换不会超过 log 个,所以我们可以暴力枚举区间起点,复杂度是 n*logn 的 #include <bits/stdc++.h> using namespa ...

  6. watch深度监测

    假设有如下代码: <div> <p>FullName: {{fullName}}</p> <p>FirstName: <input type=&q ...

  7. [转] shell逻辑运算总结, 包括[[]]与[]的区别,&&与-a的区别,||与-o的区别

    [From] https://www.cnblogs.com/tony1314/p/8315666.html 1. 关于文件和目录 -f  判断某普通文件是否存在 -d  判断某目录是否存在 -b  ...

  8. jquery-ui Datepicker 创建 销毁

    控件选项defaultDate 设置日期控件的默认日期(高亮显示的日期),如果没有设置该选项,那么就使用当前日期,这一选项只适用于input元素没有设置value属性的情况altField 额外自定一 ...

  9. python yield、yield from与协程

    从生成器到协程 协程是指一个过程,这个过程与调用方协作,产出由调用方提供的值.生成器的调用方可以使用 .send(...)方法发送数据,发送的数据会成为yield表达式的值.因此,生成器可以作为协程使 ...

  10. 【车联网T-BOX】基于CANoe实现的远程服务业务自动化测试方案

    为满足项目过程中不同阶段绝大部分测试需求,更方便快捷构造测试场景,支持异常场景测试.更早介入,不依赖周边ECU的稳定情况,专注于被测ECU.更经济,不加油,不充电,时间节省,物料节省等维度考虑.我们需 ...