This problem once again made no initialization of the problem, but the sample actually only the 2nd group is wrong, the others are right ... And it's impossible to debug ....
The problem is still a very simple form of pressure. Or the state of each row is preprocessed first. Then the state shifts from the first line down. In order to not tle, should be in each state and also pre-treatment.
The code is as follows:
#include <iostream> #include <string.h> #include <math.h> #include <queue> #include < algorithm> #include <stdlib.h> #include <map> #include <set> #include <stdio.h>using namespace std; #define LL __int64#define Pi ACOs ( -1.0) const int Mod=100000000;const int Inf=0x3f3f3f3f;const double eqs=1e -8;int dp[20][1<<16], a[1<<16], top, tot, num[16][1<<16];int mp[20][20];void init (int n) {top=0; int I, J; for (i=0;i<tot;i++) {if (!) ( i& (i<<1))) a[top++]=i; }}int Main () {int n, m, I, J, X, Max1, K, H; char c; while (scanf ("%d", &mp[0][0])!=eof) {n=1; C=getchar (); while (c!= ' \ n ') {scanf ("%d", &mp[0][n++]); C=getchar (); } for (i=1;i<n;i++) {for (j=0;j<n;j++) {scanf ("%d", &mp[i][j]); }} tot=1<<n; Init (n); memset (num,0,sizeof (num)); for (i=0;i<n; i++) {for (j=0;j<top;j++) {for (k=0;k<n;k++) {if (a[j]& (1<<k)) { NUM[I][J]+=MP[I][K]; }}}} memset (Dp,0,sizeof (DP)); max1=0; for (i=0;i<top;i++) {dp[0][i]=num[0][i]; Max1=max (Max1,dp[0][i]); } for (i=1;i<n;i++) {for (j=0;j<top;j++) {for (k=0;k<top;k++) {i F ((A[j]&a[k]) | | (a[k]& (a[j]<<1)) | | (a[j]& (a[k]<<1))) Continue; Dp[i][j]=max (Dp[i][j],dp[i-1][k]+num[i][j]); } max1=max (Max1,dp[i][j]); }} printf ("%d\n", max1); } return 0;}
HDU 2167 Pebbles (pressure DP)