Test instructions: In order you can get some value for 2^x hard drive, you can keep one and sell it later, but you can not keep other hard drives before selling, for maximum benefit
Idea: Dp[i]=min (Dp[i-1],dp[j]+2^x[j])
ImportJava.math.BigInteger;ImportJava.util.Scanner; Public classMain { Public StaticBigInteger MAX (BigInteger A,biginteger b) {if(A.compareto (b) ==1)returnA; returnb; } Public Static voidMain (string[] args) {BigInteger dp[]=Newbiginteger[5005]; BigInteger d[]=Newbiginteger[2005]; for(inti=0;i<=2000;i++){ if(i==0) d[i]=Biginteger.one; ElseD[i]=d[i-1].multiply (Biginteger.valueof (2)); } intf[]=New int[5005]; intp[]=New int[5005]; Scanner Cin=NewScanner (system.in); while(Cin.hasnext ()) {intn=Cin.nextint (); for(inti=0;i<n;i++) {String s=Cin.next (); intx=Cin.nextint (); if(S.charat (0) = = ' W ') f[i]=0; ElseF[i]=1; P[i]=x; } for(inti=0;i<n;i++) Dp[i]=Biginteger.zero; for(inti=1;i<n;i++){ if(f[i]==1){ for(intj=i-1;j>=0;j--){ if(f[j]==0&&p[i]==P[j]) {Dp[i]=max (dp[i-1], Dp[j].add (D[p[i])); Break; } Dp[i]=max (Dp[i], dp[i-1]); } } ElseDp[i]=dp[i-1]; } System.out.println (Dp[n-1]); } }}
Codeforces 18D Seller Bob DP