Description

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 i​ is described by three parameters (li, wi, hi)​ where li​ is its leap capacity, wi​ its weight, and hi​ 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 A​ climbs up on the back of frog B​ before it jumps, the first frog A​ stands a better chance of escaping the pit: it can escape if hB + lA​ is strictly larger than the depth of the pit.

Furthermore, if frog B carrying frog A on its back climbs up on the back of frog C, the situation is even better for frog A: it can now escape the pit if hC + 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 n​ and d​ (1 ≤ n ≤ 100 000​, 1 ≤ d ≤ 108​), where n​ is the number of frogs and d​ is the depth of the pit in µm. Then follow n​ lines each containing three integers l, w, h​ (1 ≤ l, w, h ≤ 108​), representing a frog with leap capacity l​ µm, weight w​ µg, and height h​ µm. The sum of all frogs' weights is at most 108​ µg.

Output

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

Sample Input

3 19
15 5 3
12 4 4
20 10 5

Sample Output

3

Hint

Source

ncpc2018

这个就是一个01背包,好难看出来啊,开始我以为是贪心,昨天的一个状压dp我也以为是贪心,

所以呢,如果我觉得像贪心但是又不能肯定的,那应该是dp

代码要是看不懂,那就模拟一次就会了

#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <iostream>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int mx = 1e5 + ;
struct node
{
int l, w, h;
}exa[mx]; bool cmp(node a,node b)
{
return a.w > b.w;
}
const int maxn = 1e8 + ;
int dp[maxn]; int main()
{
int n, d;
cin >> n >> d;
for(int i=;i<n;i++)
{
cin >> exa[i].l >> exa[i].w >> exa[i].h;
}
int ans = ;
sort(exa , exa + n, cmp);
for(int i=;i<n;i++)
{
int w = exa[i].w;
if (exa[i].l + dp[w] > d) ans++;
for(int j=;j<min(w,maxn-w);j++)
{
dp[j] = max(dp[j], dp[j + w] + exa[i].h);
}
}
cout << ans << endl;
return ;
}

2249: Altruistic Amphibians 01背包的更多相关文章

  1. 2249: Altruistic Amphibians 01背包的应用 + lh的简单图论 图转树求lca

    第一个 写了两个比较简单的数论题目,就是整除理论的两个题目,第一个题目比较蠢,第二个稍微要动一点脑筋 Codeforces Round #347 (Div. 2) – A. Complicated G ...

  2. UVALive 4870 Roller Coaster --01背包

    题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F ,     D -= K 问在D小于等于一定限度的时 ...

  3. POJ1112 Team Them Up![二分图染色 补图 01背包]

    Team Them Up! Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7608   Accepted: 2041   S ...

  4. Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)

    传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...

  5. 51nod1085(01背包)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085 题意: 中文题诶~ 思路: 01背包模板题. 用dp[ ...

  6. *HDU3339 最短路+01背包

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  7. codeforces 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses ——(01背包变形)

    题意:给你若干个集合,每个集合内的物品要么选任意一个,要么所有都选,求最后在背包能容纳的范围下最大的价值. 分析:对于每个并查集,从上到下滚动维护即可,其实就是一个01背包= =. 代码如下: #in ...

  8. POJ 3624 Charm Bracelet(01背包)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34532   Accepted: 15301 ...

  9. (01背包变形) Cow Exhibition (poj 2184)

    http://poj.org/problem?id=2184   Description "Fat and docile, big and dumb, they look so stupid ...

随机推荐

  1. 试验使用t检验

    官方解释 Excel中使用T.TEST函数 T.TEST(array1,array2,tails,type) Array1      必需.第一个数据集. Array2      必需.第二个数据集. ...

  2. commonJS、AMD和CMD之间的区别

    JS中的模块规范(CommonJS,AMD,CMD),如果你听过js模块化这个东西,那么你就应该听过或CommonJS或AMD甚至是CMD这些规范咯,我也听过,但之前也真的是听听而已. 现在就看看吧, ...

  3. Python变量详解

    Python变量详解 目录 Python变量详解 一.变量的定义 二.变量组成的三部分 2.1 变量名 2.1.1 变量名的命名规范 2.1.2 变量名的命名风格 2.2 赋值符号 2.3 变量值 三 ...

  4. Linux学习笔记(六)压缩和解压缩命令

    压缩和解压缩命令 zip unzip gzip gunzip bzip2 bunzip2 tar zip (.zip格式的压缩文件) 英文原意:package and compress (archiv ...

  5. 如何防止CDN防护被绕过

    当攻击者发现目标站点存在CDN防护的时候,会尝试通过查找站点的真实IP,从而绕过CDN防护.我们来看一个比较常见的基于公有云的高可用架构,如下:CDN(入口层)->WAF(应用层防护)-> ...

  6. 小程序里button边框有黑线解决办法(自定义button样式)

    .go_to_user::after{ border:1px solid transparent; } button的class为go_to_user button{ padding:; box-si ...

  7. weblogic补丁升级详细步骤,18.7.17补丁更新

    weblogic打补丁 到weblogic官网下载补丁包 对应的补丁包  如: p22248372_1036012_Generic.zip 一  安装补丁步骤 1.登录linux的weblogic用户 ...

  8. 搭建phpMyAdmin

    MySQL常见的管理工具 今天选择的phpMyAdmin 一款基于浏览器管理数据库的工具. 下载可以去官网下载https://files.phpmyadmin.net/phpMyAdmin/4.7.5 ...

  9. Linux C语言 检测文件是否存在

    头文件 unistd.h ) { // file exists } else { // file doesn't exist } You can also use R_OK, W_OK, and X_ ...

  10. lodctr /R 失败的情况

    I've resolved with the following steps: PS C:\Windows\system32> cmd Microsoft Windows [Version 6. ...