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. java的排序算法

    分享网页:https://yq.aliyun.com/articles/136085?utm_content=m_26483

  2. shell__常用命令__grep

    grep | zgrep (不用解压zip就能直接搜索) -i 不区分大小写 -I 忽略二进制文件 -R或r 递归文件目录 -c 计算找到的总数量 -n 显示行号 -v 显示不包含匹配文本的所有行 - ...

  3. loj6570 毛毛虫计数(生成函数FFT)

    link 巨佬olinr的题解 <-- olinr很强 考虑生成函数 考虑直径上点数>=4的毛毛虫的直径,考虑直径中间那些节点以及他上面挂的那些点的EGF \(A(x)=\sum_{i\g ...

  4. es查询,聚合、平均值、值范围、cardinality去重查询

    原文:https://blog.csdn.net/sxf_123456/article/details/78195829 普通查询 GET ana-apk/_search { "query& ...

  5. leetcode-806-Number of Lines To Write String

    题目描述: We are to write the letters of a given string S, from left to right into lines. Each line has ...

  6. Jquery sblings

    $("给定元素").siblings(".selected") 中的(".selected")表示筛选给定元素类名为.selected的同胞 ...

  7. 对路径访问拒绝,要加上具体filename/c.png

    string strPath = Path.Combine(FilePath, DateTime.Now.ToString("yyyy-MM-dd")); if (!Directo ...

  8. Saiku2.6 配置数据源

    把连接字符串和Schema文件放这里.

  9. django 中的聚合和分组 F查询 Q查询 事务cookies和sessions 066

    1 聚合和分组 聚合:对一些数据进行整理分析 进而得到结果(mysql中的聚合函数) 1aggregate(*args,**kwargs) : 通过对QuerySet进行计算 ,返回一个聚合值的字典. ...

  10. centsos 查看系统版本信息

    [root@hostuser gitlab]# lsb_release -a LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cx ...