Topic Portal
/*Test Instructions: Two rows of numbers, adjacent columns one up, or two rows apart, select the number and maximum DP from left to right: state transition equation: dp[i][j] = max (Dp[i][j], dp[1-i][j-1] + a[i][j], dp[i/1-i][j -2] + a[i][j]); To push it from the previous turn, I write the reverse, the internal strength is not enough: (*/#include<cstdio>#include<algorithm>#include<iostream>#include<cstring>#include<cmath>#include<string>#include<vector>#include<queue>#include<map>#include<Set>#include<ctime>#include<cstdlib>using namespacestd;Const intMAXN = 1e5 +Ten;Const intINF =0x3f3f3f3f;inta[2][MAXN];intdp[2][MAXN];intMainvoid)//uvalive 6506 Padovan Sequence{//freopen ("k.in", "R", stdin); intT scanf ("%d", &t); while(t--) { intN scanf ("%d", &N); Memset (DP,0,sizeof(DP)); for(intI=0; i<=1; ++i) { for(intj=1; j<=n; ++j) {scanf ("%d", &A[i][j]); }} dp[0][1] = a[0][1]; dp[1][1] = a[1][1]; intans = max (dp[0][1], dp[1][1]); for(intj=2; j<=n; ++j) { for(intI=0; i<=1; ++i) {dp[i][j]= Max (Dp[i][j], dp[1-i][j-1] +A[i][j]); if(J >2) {Dp[i][j]= Max (Dp[i][j], dp[i][j-2] +A[i][j]); DP[I][J]= Max (Dp[i][j], dp[1-i][j-2] +A[i][j]); } ans=Max (ans, dp[i][j]); }} printf ("%d\n", ans); } return 0;}
DP uvalive 6506 Padovan Sequence