A. Altruistic Amphibians

Upsolved.

题意:

$有n只青蛙,其属性用三元组表示 <l_i, w_i, h_i> l_i是它能跳的高度,w_i是它的体重,h_i是它的身高$

一只青蛙的承重不能超过它的体重,它可以踩在别的青蛙上面跳

一口井的深度为$d, 一只青蛙能够跳出去当且仅当它离井口的距离严格小于它的l_i$

$离井口的距离为d - 它所踩的青蛙的身高和,当然可以不踩其他青蛙$

求最多跳出去多少只青蛙

思路:

显然,重量最大的青蛙肯定只能在最下面

那么按重量大小排个序

然后考虑递推到下面

$dp[i] 表示 重量为i的青蛙最高能处在什么样的高度$

$dp[j - a[i].w] = dp[j] +a[i].h \;\;j \in [a[i].w, 2 * a[i].w)$

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define ll long long
 5 #define N 100010
 6 const int D = (int)1e8 + 10;
 7 int n, d;
 8 struct node
 9 {
10     int l, w, h;
11     void scan() { scanf("%d%d%d", &l, &w, &h); }
12     bool operator < (const node &r) const { return w > r.w; }
13 }a[N];
14 int dp[D];
15 
16 int main()
17 {
18     while (scanf("%d%d", &n, &d) != EOF)
19     {
20         for (int i = 1; i <= n; ++i) a[i].scan();
21         sort(a + 1, a + 1 + n);
22         int res = 0;
23         for (int i = 1; i <= n; ++i)
24         {
25             if (dp[a[i].w] + a[i].l > d) ++res;
26             for (int j = a[i].w; j < min(2 * a[i].w, (int)1e8 + 2); ++j)
27                 dp[j - a[i].w] = max(dp[j - a[i].w], dp[j] + a[i].h);
28         }
29         printf("%d\n", res); 
30     }
31     return 0;
32 }
View Code

相关文章:

  • 2022-12-23
  • 2021-05-22
  • 2021-09-17
  • 2021-09-22
  • 2021-12-07
  • 2021-09-10
  • 2022-01-03
  • 2021-11-23
猜你喜欢
  • 2021-11-24
  • 2021-05-23
  • 2021-10-28
  • 2021-10-24
  • 2021-11-15
相关资源
相似解决方案