太空电梯

  题目大意:一群牛想造电梯到太空,电梯都是由一个一个块组成的,每一种块不能超过这个类型的高度,且每一种块都有各自的高度,有固定数量,问最高能造多高。

  这题就是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;
}
}
}

最新文章

  1. leetcode 142. Linked List Cycle II
  2. Starting MySQL.The server quit without updating PID file (xxxx.pid).[FAILED]
  3. 计算机视觉(Computer Version,CV)、模式识别、人工智能
  4. atitit.提升开发效率---动态语言总结
  5. Laravel在不同的环境调用不同的配置文件
  6. Codeforce Round #226 Div2
  7. Gradle的配置实例
  8. html5 base64基础
  9. HDU5777 domino (BestCoder Round #85 B) 思路题+排序
  10. HTML5 新功能
  11. xcode忽略警告
  12. [置顶] Ftp客户端概要设计
  13. HTML的TextArea标记跟随文本内容自动设置高度
  14. 如何在centos操作系统上发布.net core的项目
  15. react中的路由配置踩坑记
  16. 用JQuery操作元素的style属性
  17. Spring Boot引起的“堆外内存泄漏”排查及经验总结
  18. CF487E Tourists - Tarjan缩点 + 树剖 + multiset
  19. [转]MySQL update join语句
  20. [note]Why I haven’t quit my corporate job (yet)

热门文章

  1. 用freemarker生产静态页面
  2. 【Matplotlib】绘图常见设置说明
  3. 【poj3233】 Matrix Power Series
  4. eclipse中python文本字体大小设置
  5. POJ2392Space Elevator(贪心+背包)
  6. jquery------.resizable()的使用
  7. CSS制作图片水平垂直居中
  8. pthread_rwlock
  9. C/C++中的getline函数总结:
  10. 15个超实用的php正则表达式