HDU-3033 scrolling array with pits

Source: Internet
Author: User

At least one of each layer, when rolling to a layer of illegal or not, so every time to memset

#include <bits/stdc++.h>#define REP (i,j,k) for (int i=j;i<=k;i++)#define RREP (i,j,k) for (int i=j;i>=k;i--)#define SCAN (a) scanf ("%d", &a)using namespaceStdConst intMAXN =5e5+11;Const intOO =0x3f3f3f3f;intN,m,k;typedefpair<int,int> p;vector<p> vec[ -];intdp[2][MAXN];intMain () { while(SCANF ("%d%d%d", &n,&m,&k)!=eof) {Rep (I,1, K) vec[i].clear (); Rep (I,1, N) {intA,b,c; scanf"%d%d%d", &a,&b,&c);         Vec[a].push_back (P (b,c)); }BOOLflag=0; Rep (I,1Kif(!vec[i].size ()) flag=1;if(flag) {printf ("Impossible\ n");Continue; } Rep (I,0, m) dp[0][i]=0; Rep (I,1, K) {memset (dp[i&1],0x80,sizeofdp[i&1]);//Note when scrolling             for(AutoK:vec[i]) {Rrep (J,m,k.first) {intC=k.first,w=k.second; dp[i&1][j]=max (dp[i&1][j],max (dp[i&1][j-c]+w,dp[i-1&1][J-C]+W)); }            }        }if(dp[k&1][m]<0) printf ("Impossible\ n");Elseprintf"%d\n",dp[k&1][m]); }return 0;}

HDU-3033 scrolling array with pits

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.