传送门:

题面:

A. Altruistic Amphibians

time limit per test

3.0 s

memory limit per test

512 MB

input

standard input

output

standard output

A set of frogs have accidentally fallen to the bottom of a large pit. Their only means of escaping the pit is to jump out of it. Each frog ii is described by three parameters (li,wi,hi)(li,wi,hi) where lili is its leap capacity, wiwi its weight, and hihi its height. The leap capacity specifies how high that frog can jump. If a frog's leap capacity is strictly larger than the depth of the pit, the frog can directly escape the pit. However, these frogs are altruistic. Rather than selfishly saving themselves and leaving the frogs with too limited leap capacity behind, they collectively aim to save as many of them from the pit as possible.

The frogs realize that if a frog AA climbs up on the back of frog BB before it jumps, the first frog AA stands a better chance of escaping the pit: it can escape if hB+lAhB+lA is strictly larger than the depth of the pit.

Furthermore, if frog BB carrying frog AA on its back climbs up on the back of frog CC, the situation is even better for frog AA: it can now escape the pit if hC+hB+lAhC+hB+lA is strictly larger than the depth of the pit.

The frogs can build even higher piles of frogs this way, the only restriction is that no frog may carry other frogs of weight in total amounting to its own weight or heavier. Once a pile has been used to allow a frog to escape, the frogs in the pile jump back to the bottom of the pit and they can then form a new pile (possibly consisting of a different set of frogs). The question is simply how many frogs can escape the pit assuming they collaborate to maximize this number?

Input

The first line of input contains two integers nn and dd (1≤n≤1000001≤n≤100000, 1≤d≤1081≤d≤108), where nn is the number of frogs and dd is the depth of the pit in μmμm. Then follow nn lines each containing three integers l,w,hl,w,h (1≤l,w,h≤1081≤l,w,h≤108), representing a frog with leap capacity ll μmμm, weight ww μgμg, and height hh μmμm. The sum of all frogs' weights is at most 108108 μgμg.

Output

Output the maximum number of frogs that can escape the pit.

Examples

input

Copy

3 19
15 5 3
12 4 4
20 10 5

output

Copy

3

input

Copy

3 19
14 5 3
12 4 4
20 10 5

output

Copy

2

题意:

有n个青蛙被困在了一口深度为d的井里,对于每个青蛙有三种参数(l,w,h)分别代表它的最大跳跃的高度,它的体重以及它的身高。现在他们打算采用叠罗汉的方式让尽可能多的青蛙逃离这口井,但在叠罗汉的过程中,上面的青蛙的重量要严格小于下面的青蛙的重量。现在问你最多能够有多少只青蛙能够成功逃生。

题目分析:

一个挺有意思的题目。首先考虑这样的问题:倘若要让尽可能多的青蛙能够逃跑,则显然罗汉最好叠得尽可能的高(这才能使得那些不能一次性跳出的青蛙能够逃离)。

而显然,对于那些体重最大的青蛙,他们显然不能叠在其他青蛙上,因此我们首先对青蛙的重量从大到小进行排序,其次我们考虑第i个青蛙的重量对于其他重量小的重量的青蛙的状态的转移。

我们设为重量为i的青蛙最高能够跳的高度,而对于第i个重量为的青蛙,不难想到最多一定会有个重量小于的青蛙能够跳到它的上面,故可得有状态转移方程

代码:

#include <bits/stdc++.h>
#define maxn 100000005
using namespace std;
int dp[maxn];
struct Node{int l,w,h;bool operator <(const Node &b)const{return w>b.w;}
}q[100005];
int main()
{int n,d;scanf("%d%d",&n,&d);for(int i=0;i<n;i++) scanf("%d%d%d",&q[i].l,&q[i].w,&q[i].h);sort(q,q+n);int res=0;for(int i=0;i<n;i++){if(dp[q[i].w]+q[i].l>d) res++;for(int j=q[i].w;j<min(2*q[i].w,(int)1e8+2);j++){dp[j-q[i].w]=max(dp[j-q[i].w],dp[j]+q[i].h);}}printf("%d\n",res);
}

转载于:https://www.cnblogs.com/Chen-Jr/p/11007170.html

Gym 101933 A(dp)相关推荐

  1. 求三角形最大面积(DP)

    求三角形最大面积(DP) 在OJ上奇迹般WA了:WA:70. Why? #include <iostream> #include <string.h> using namesp ...

  2. LeetCode 编辑距离 II(DP)

    1. 题目 给你两个单词 s 和 t,请你计算出将 s 转换成 t 所使用的最少操作数. 你可以对一个单词进行如下两种操作: 删除一个字符 替换一个字符 注意: 不允许插入操作 题目保证有解 示例: ...

  3. LeetCode 1220. 统计元音字母序列的数目(DP)

    文章目录 1. 题目 2. 解题 1. 题目 给你一个整数 n,请你帮忙统计一下我们可以按下述规则形成多少个长度为 n 的字符串: - 字符串中的每个字符都应当是小写元音字母('a', 'e', 'i ...

  4. LeetCode 265. 粉刷房子 II(DP)

    文章目录 1. 题目 2. 解题 1. 题目 假如有一排房子,共 n 个,每个房子可以被粉刷成 k 种颜色中的一种,你需要粉刷所有的房子并且使其相邻的两个房子颜色不能相同. 当然,因为市场上不同颜色油 ...

  5. LeetCode 256. 粉刷房子(DP)

    文章目录 1. 题目 2. 解题 1. 题目 假如有一排房子,共 n 个,每个房子可以被粉刷成红色.蓝色或者绿色这三种颜色中的一种,你需要粉刷所有的房子并且使其与相邻的两个房子颜色不能相同. 当然,因 ...

  6. LeetCode 1223. 掷骰子模拟(DP)

    1. 题目 有一个骰子模拟器会每次投掷的时候生成一个 1 到 6 的随机数. 不过我们在使用它时有个约束,就是使得投掷骰子时,连续 掷出数字 i 的次数不能超过 rollMax[i](i 从 1 开始 ...

  7. LeetCode 1155. 掷骰子的N种方法(DP)

    1. 题目 这里有 d 个一样的骰子,每个骰子上都有 f 个面,分别标号为 1, 2, -, f. 我们约定:掷骰子的得到总点数为各骰子面朝上的数字的总和. 如果需要掷出的总点数为 target,请你 ...

  8. LeetCode 1139. 最大的以 1 为边界的正方形(DP)

    1. 题目 给你一个由若干 0 和 1 组成的二维网格 grid,请你找出边界全部由 1 组成的最大 正方形 子网格,并返回该子网格中的元素数量.如果不存在,则返回 0. 示例 1: 输入:grid ...

  9. 程序员面试金典 - 面试题 17.23. 最大黑方阵(DP)

    1. 题目 给定一个方阵,其中每个单元(像素)非黑即白. 设计一个算法,找出 4 条边皆为黑色像素的最大子方阵. 返回一个数组 [r, c, size] ,其中 r, c 分别代表子方阵左上角的行号和 ...

最新文章

  1. Java学习笔记(二)--Java开发环境
  2. leetcode 434. 字符串中的单词数(Java版)
  3. 感知算法论文(六):LEDNet(2019)
  4. BlogEngine学习二:基于ICallbackEventHandler的轻量级Ajax方式
  5. easyui combobox根据输入内容动态查找_制作智能下拉菜单,自动筛选想要输入的数据,同事都看呆了...
  6. 高中会教师证有计算机专业吗,教师资格证 --高中信息技术篇
  7. Android PreferenceScreen的使用和详解(设置页面)
  8. veeam_backup的几种备份方式
  9. WEB学习第四天(网页模型
  10. html 文字阴影 一重投影,鼠标移入文字添加阴影 溢出的文字 添加多重颜色
  11. 【OpenCVOpenGLMarkerless AR】原理部分+代码
  12. 尺度空间-多尺度特征空间
  13. [完]PHP 格式化显示时间 date() 函数
  14. C# 文件搜索过程中如何提取office文件,wps,pdf,html,eml等格式的文件正文
  15. Python enumerate,iter的用法
  16. 漫威电影和程序员、Git 到底有什么关系?
  17. matlab中的~用法和~=
  18. Ubuntu16.04+智能车+YOLO
  19. 电脑桌面快捷方式更换图片
  20. 民航导航技术发展及北斗应用分析

热门文章

  1. 基于TensorFlow,人声识别如何在端上实现?
  2. AMD RX 8000系列将采用3纳米和5纳米工艺
  3. 软件技术专业-就业提示(二、测试工程师)
  4. jsonp的原理·jsonp是不是ajax中实现跨域访问的技术
  5. 判断当前时间是否在某个时间范围内
  6. MySQL5.6 选项和变量整理
  7. Linux Shell编程第四篇case语句
  8. 程序员必备:提升开发效率神器,强烈推荐 !!!
  9. 【学习】SpringBoot之自定义拦截器
  10. Linux文件atime ctime mtime