P1086

时间限制: 1 Sec  内存限制: 128 MB
提交: 38  解决: 27
[提交][状态][讨论版][命题人:外部导入]

题目描述

现有N种箱子,每种箱子高度H_i,数量C_i。现选取若干箱子堆成一列,且第i种箱子不能放在高度超过A_i的地方。试求最大叠放高度。

输入

第一行,一个整数,表示箱子种类N。 接下来N行,每行三个整数,表示H_i,A_i,C_i。

输出

一个整数,表示最大高度。

样例输入

3
7 40 3
5 23 8
2 52 6

样例输出

48

提示

N  < =  400  ,  H_i  < =  100  ,  C_i  < =  10  ,  A_i  < =  40000

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
int n;
int H,C,A;
struct BOX
{
int h,a,c;
}box[];
bool cmp(BOX x,BOX y)
{
return x.a<y.a;
}
int main()
{
cin>>n;
int num=;
for(int i=;i<=n;i++)
{
cin>>box[i].h>>box[i].a>>box[i].c;
}
sort(box+,box++n,cmp);
bool f[];
memset(f,,sizeof(f));
f[]=;
int ans=;
for(int i=;i<=n;i++)
{
for(int j=;j<=box[i].c;j++)
{
for(int k=box[i].a;k>=box[i].h;k--)
{
if(f[k-box[i].h])
f[k]=;
if(f[k]) ans = max(ans,k);
}
}
}
cout<<ans;
return ;
}

堆叠箱子(基础dp)的更多相关文章

  1. 基础dp

    队友的建议,让我去学一学kuangbin的基础dp,在这里小小的整理总结一下吧. 首先我感觉自己还远远不够称为一个dp选手,一是这些题目还远不够,二是定义状态的经验不足.不过这些题目让我在一定程度上加 ...

  2. 基础DP(初级版)

    本文主要内容为基础DP,内容来源为<算法导论>,总结不易,转载请注明出处. 后续会更新出kuanbin关于基础DP的题目...... 动态规划: 动态规划用于子问题重叠的情况,即不同的子问 ...

  3. hdu 5586 Sum 基础dp

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Desc ...

  4. hdu 4055 Number String (基础dp)

    Number String Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. 训练指南 UVA - 10917(最短路Dijkstra + 基础DP)

    layout: post title: 训练指南 UVA - 10917(最短路Dijkstra + 基础DP) author: "luowentaoaa" catalog: tr ...

  6. 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP)

    layout: post title: 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP) author: "luowentaoaa" catalog: true ...

  7. 「kuangbin带你飞」专题十二 基础DP

    layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...

  8. M - 基础DP

    M - 基础DP Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Descriptio ...

  9. lightoj1004【基础DP】

    从低端到顶端求个最大值: 思路: 基础DP,递推 #include<cstdio> #include<queue> #include<map> #include&l ...

随机推荐

  1. Hive错误:java.net.ConnectException: Connection refused: connect

    修改hive配置文件 hive-site.xml,加入如下配置项: <property> <name>hive.server2.thrift.port</name> ...

  2. KMP算法自我理解 和 模板

    字符串   abcd abc abcd abc 匹配串   cdabcd 匹配串的 next  0 0 0 0 1 2: 开始匹配 abcd abc abcd abc cd abc d a,d 匹配失 ...

  3. HNOI2019 简要题解

    HNOI 2019 简要题解 没想到自己竟也能有机会写下这篇题解呢. LOJ Luogu Day1T1 鱼 枚举\(AD\)两点后发现\(BC\)与\(EF\)相对独立,因此只需要计算合法的\(BC\ ...

  4. Go Example--闭包

    package main import "fmt" func main() { //这里需要将闭包函数当作一个类理解,这里是实例化 nextInt := intSeq() fmt. ...

  5. LeetCode - Kth Largest Element in a Stream

    Design a class to find the kth largest element in a stream. Note that it is the kth largest element ...

  6. msyql多个or,and,

    where (`to`= 2 and `from`= 8) or (`to`= 8 and `from`= 2) and from_unixtime(a.time,'%Y-%m-%d') ='2017 ...

  7. Maven知识整理

    一.概念: Maven是一个项目管理工具,它包含了一个项目对象模型(Project Object Model),一组标准集合,一个项目生命周期(Project Lifecycle),一个依赖管理系统( ...

  8. [转]Java NIO通俗易懂简明教程

    Java NIO(New IO)是从Java 1.4版本开始引入的一个新的IO API,可以替代标准的Java IO API.本系列教程将有助于你学习和理解Java NIO. Java NIO提供了与 ...

  9. TypeScript 知识点

    TypeScript 通过 类型批注 提供静态类型以在编译时启动类型检查. 基本批注类型是number.bool.string.而弱或动态类型是any. typescript 使用 作用 语句 全局安 ...

  10. 将 vue 挂在 window 对象上,实现能调用 elementUI 的组件

    html 部分: <div id="sample"> </div> js 部分(将js代码放在 body 的 onload事件中: <body onl ...