Transmission Door
Idea: Classic DP problem, I come to water a water, see the data range should be able to know this is a multidimensional DP, we can set F (I,J,k,L,m) I walked the first card with J, the 2nd card with K, the 3rd card with L, the 4th card with the maximum score after M. But we found that this transfer, not only the memory is not open, and the transfer time will be timed out, what to do, we found that the five number is not independent, you can know 4 for 5, so we can simply omit 1 dimensions into 4 dimensional space, it can be opened.
Code:
#include <cstdio>InlineintMaxintAintb) {returnA>B?A:B;}intNm;inta[355], card[5];intf[ A][ A][ A][ A];intMain () {inti,k,j,l; scanf"%d%d",&n,&m); for(i =1; I <= N; i + +) scanf ("%d", &a[i]); for(i =1; I <=m; i + +) {scanf ("%d", &j); card[j]++; } for(i=0; i<=card[1]; i + +) for(j=0; j<=card[2]; J + +) for(k=0; k<=card[3]; K + +) for(l=0; l<=card[4]; L + +) {intA1 = i==0?0: f[i-1][J][K][L];intA2 = j==0?0: f[i][j-1][K][L];intA3 = k==0?0: f[i][j][k-1][L];inta4 = l==0?0: f[i][j][k][l-1];intt = max (max (A1,A2), Max (A3,A4)); F[I][J][K][L] = t+a[i+2*j+3*k+4*l+1]; }printf("%d", f[card[1]][card[2]][card[3]][card[4]]);}
Copyright NOTICE: Please feel free to reprint O (∩_∩) o
[NOIP2010] Turtle chess (DP)