DP:Space Elevator(POJ 2392)
2024-10-09 22:42:25
题目大意:一群牛想造电梯到太空,电梯都是由一个一个块组成的,每一种块不能超过这个类型的高度,且每一种块都有各自的高度,有固定数量,问最高能造多高。
这题就是1742的翻版,对ai排个序就可以了
(尼玛,我qsort排了n-1个数,wa半天不知所措)
#include <iostream>
#include <functional>
#include <algorithm> using namespace std;
typedef struct _set
{
int h_i;
int max_h;
int count;
}Block;
int fcomp(const void *a, const void *b)
{
return (*(Block *)a).max_h - (*(Block *)b).max_h;
} static int dp[];
static Block B_Set[]; void Search(const int); int main(void)
{
int n;
while (~scanf("%d", &n))
{
if (n == ) continue;
for (int i = ; i <= n; i++)
scanf("%d%d%d", &B_Set[i].h_i, &B_Set[i].max_h, &B_Set[i].count);
qsort(B_Set, n + , sizeof(Block), fcomp);
Search(n);
}
return ;
} void Search(const int n)
{
int i, j;
memset(dp, -, sizeof(dp));
dp[] = ;
for (i = ; i <= n; i++)
{
if (B_Set[i].h_i == ) continue;
for (j = ; j < B_Set[i].h_i && j <= B_Set[i].max_h; j++)//先把前面的几个包确定下来
if (dp[j] != -)
dp[j] = B_Set[i].count;
for (; j <= B_Set[i].max_h; j++)
{
if (dp[j] == -)
{
if (dp[j - B_Set[i].h_i] <= )
continue;
else dp[j] = dp[j - B_Set[i].h_i] - ;
}
else dp[j] = B_Set[i].count;
}
}
for (int i = B_Set[n].max_h; i >= ; i--)
{
if (dp[i] >-)
{
printf("%d\n", i);
break;
}
}
}
最新文章
- leetcode 142. Linked List Cycle II
- Starting MySQL.The server quit without updating PID file (xxxx.pid).[FAILED]
- 计算机视觉(Computer Version,CV)、模式识别、人工智能
- atitit.提升开发效率---动态语言总结
- Laravel在不同的环境调用不同的配置文件
- Codeforce Round #226 Div2
- Gradle的配置实例
- html5 base64基础
- HDU5777 domino (BestCoder Round #85 B) 思路题+排序
- HTML5 新功能
- xcode忽略警告
- [置顶] Ftp客户端概要设计
- HTML的TextArea标记跟随文本内容自动设置高度
- 如何在centos操作系统上发布.net core的项目
- react中的路由配置踩坑记
- 用JQuery操作元素的style属性
- Spring Boot引起的“堆外内存泄漏”排查及经验总结
- CF487E Tourists - Tarjan缩点 + 树剖 + multiset
- [转]MySQL update join语句
- [note]Why I haven’t quit my corporate job (yet)