2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) A. altruistic amphibians DP

Source: Internet
Author: User

Link: https://codeforc.es/gym/101933/problem/A

N frogs are in one pit, and the maximum number of frogs that can jump out of the pit is required. Each frog has three attributes: L is the height of a frog that can be jumped at a time, W is the weight of the frog, and H is the height of the frog when it is used as the cushion, the premise is that the frog's weight is smaller than the total weight of the frog above him.

Question: first, sort the frogs by weight. DP [J] indicates that the frog that has been carried in the back can also put a weight <j's maximum height of the back when the frog is updated, because the weights are sorted in ascending order, DP [J] is composed of DP [J + A [I]. w] transferred to indicate the maximum height of the current frog at the top. For details, see the code ~

 

 1 #include <bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 #define ull unsigned long long 5 #define mst(a,b) memset((a),(b),sizeof(a)) 6 #define mp(a,b) make_pair(a,b) 7 #define pi acos(-1) 8 #define pii pair<int,int> 9 #define pb push_back10 const int INF = 0x3f3f3f3f;11 const double eps = 1e-6;12 const int MAXN = 1e5 + 10;13 const int MAXM = 1e8 + 10;14 const ll mod = 1e9 + 7;15 16 struct node {17     int l,w,h;18 }a[MAXN];19 20 bool cmp(node x,node y) {21     return x.w > y.w;22 }23 24 int dp[MAXM];25 26 int main() {27 #ifdef local28     freopen("data.txt", "r", stdin);29 //    freopen("data.txt", "w", stdout);30 #endif31     mst(dp, 0);32     int n,d;33     scanf("%d%d",&n,&d);34     for(int i = 0; i < n; i++)35         scanf("%d%d%d",&a[i].l,&a[i].w,&a[i].h);36     sort(a,a + n,cmp);37     int ans = 0;38     for(int i = 0; i < n; i++) {39         if(dp[a[i].w] + a[i].l > d) ans++;40         int mx = min((int)1e8 - a[i].w, a[i].w);41         for(int j = 1; j < mx; j++) {42             dp[j] = max(dp[j],dp[j + a[i].w] + a[i].h);43             if(dp[j] > MAXM) dp[j] = MAXM;44         }45     }46     printf("%d\n",ans);47     return 0;48 }

 

2018-2019 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2018) A. altruistic amphibians DP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.