日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Gym 101933 A(dp)

發布時間:2024/7/5 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Gym 101933 A(dp) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

傳送門:

題面:

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)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 精品精品视频 | 五月婷婷av | 亚洲欧美国产高清 | 国产欧美综合一区二区三区 | 欧美少妇bbw | 视频一区二区视频 | 凹凸精品一区二区三区 | 萌白酱一区二区 | 亚洲AV成人无码电影在线观看 | 亚洲国产综合av | 亚洲一区视频在线 | 成人 黄 色 免费播放 | 亚洲中文字幕无码不卡电影 | 韩日av| 91一区二区三区 | 永久免费看黄网站 | 国产激情久久久 | 欧美色鬼 | 免费毛片在线播放免费 | 好吊操这里只有精品 | 成人免费在线视频 | 国产精品久久久久久精 | 在线免费一区 | ktv做爰视频一区二区 | 亚洲精品国产精品国自产网站 | 成人tiktok黄短视频 | 成年网站在线 | 高清亚洲| 一区二区天堂 | 国产精品人人人人 | 69sex久久精品国产麻豆 | 国产毛片在线看 | 日韩精品在线第一页 | 三级黄色片网站 | 亚洲午夜精品久久 | 日本不卡中文字幕 | 欧美另类精品 | 亚洲av鲁丝一区二区三区 | 国产一区亚洲二区三区 | 伦伦影院午夜理伦片 | 国产精品三级 | 亚洲午夜精品在线 | 亚洲免费三级 | 啦啦啦免费高清视频在线观看 | 欧美影院一区二区 | 成年人在线播放 | 免费福利小视频 | 精品国产一区二区三区四区 | 中文字幕在线播放av | 美女被捅个不停 | 五月天激情啪啪 | 国产精品久久国产 | 玖玖在线播放 | 日韩精品久久一区二区 | 免费看色 | 精品日韩在线播放 | 国产精品久久久久久免费免熟 | 韩国精品久久久 | 亚洲AV无码一区二区三区蜜桃 | 亚洲成人7777| 在线视频成人 | 婷婷综合影院 | 成人av影院在线观看 | 小向美奈子在线观看 | 最新不卡av | 网红av在线| 久久一区二区电影 | 国产微拍精品一区 | 久久久999精品视频 国产在线xx | 青青草手机视频在线观看 | 福利亚洲| 欧美日韩精品免费 | 欧美一区二区黄片 | 校园伸入裙底揉捏1v1h | 国产三级三级在线观看 | 亚洲深夜视频 | 国语对白 | 日本少妇喷水视频 | 久久偷看各类wc女厕嘘嘘偷窃 | 天堂√8在线中文 | 日本一区欧美 | 久草综合网 | 国产精品电影 | 国产精品毛片久久久久久 | 一级 黄 色 片69 | www.亚洲天堂.com | 色噜噜综合| 亚洲乱码国产乱码精品精大量 | 91福利影院 | 探花一区 | 中文字幕亚洲精品在线观看 | 欧美大胆a | 91成人在线 | 女女调教被c哭捆绑喷水百合 | 美女毛片在线观看 | 香蕉911 | 精品美女一区二区 | 伊人色影院 | 二色av|