POJ 2392 Space Elevator 排序+多重背包
来源:互联网 发布:节奏大师网络拦截 编辑:程序博客网 时间:2024/06/06 19:00
题目链接
题目大意,给你一些块,每个块的高度为Hi,能堆到最大高度为Ai,能使用的次数为Ci。问你最大能堆多大的高度。
很明显多重背包,但是不用计数什么的,就用dp[i]表示能不能到达i
然后递推的时候更新最大值。
但是有一个点需要考虑,一个是需要排序,就是先选Ai小的物品,这样才可能堆的高。
下面贴代码
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;struct po{ int h,a,c;};bool cmp(po a,po b){ return a.a<=b.a;}po mm[410];int sum[410000];int dp[400010];int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d%d",&mm[i].h,&mm[i].a,&mm[i].c); sort(mm,mm+n,cmp); memset(dp,0,sizeof(dp)); dp[0] = 1;//初始化 int ans = 0; for(int i=0;i<n;i++){ memset(sum,0,sizeof(sum));//计数用了多少个 for(int j=mm[i].h;j<=mm[i].a;j++){ if(!dp[j] && dp[j-mm[i].h] && sum[j-mm[i].h] < mm[i].c){ dp[j] = 1; ans = max(ans,j); sum[j] = sum[j-mm[i].h] + 1; } } } printf("%d\n",ans); return 0;}
dp动态规划还是得多敲,这个东西,经验很重要,对于我这个渣渣来说。
0 0
- poj 2392 Space Elevator(排序+多重背包)
- POJ 2392 Space Elevator 排序+多重背包
- POJ Space Elevator(排序+多重背包)
- poj 2392 Space Elevator(dp 排序+多重背包)
- POJ 2392 Space Elevator(排序处理多重背包)
- poj 2392 Space Elevator 多重背包
- poj 2392 Space Elevator(多重背包变形)
- POJ 2392 Space Elevator [DP 多重背包]
- POJ 2392 Space Elevator (多重背包)
- POJ 2392 Space Elevator (多重背包问题)
- POJ 2392 Space Elevator 多重背包
- POJ 2392 Space Elevator (多重背包+优化)
- poj 2392 Space Elevator (多重背包)
- poj 2392 Space Elevator(多重背包)
- POJ 2392 Space Elevator 多重背包
- poj 2392 Space Elevator (多重背包)
- POJ 2392-Space Elevator(多重背包)
- POJ 2392 Space Elevator(贪心+多重背包)
- mybatis注解详解
- hdu 4474 bfs
- java 路径分隔符
- 递归
- Android学习笔记--RecycleView用法
- POJ 2392 Space Elevator 排序+多重背包
- Android handler示例
- linux jdk安装配置
- 记毕业感悟160727
- WebGL学习笔记(二)
- 弹出框日历自己写的...
- AndroidStudio 快捷键 Ctrl+Alt+left 不能用
- Android插件-动态加载
- 友盟统计使用记录