And hang on the stone to take the problem is almost more than a diagonal also not the next is the input format
Pre-processing all the states that satisfy a row are listed and the corresponding and calculated
And then according to the DP corresponding ideas to ask
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace Std;
int num[20][20];
int mark[1<<16];
int sum[20][1<<16],have[100000],cont;
int n;
int deal ()
{
int i;
cont=0;
int t=1<<n;
memset (sum,0,sizeof (sum));
printf ("%d\n", t);
for (i=0;i<t;i++)
{
if (i& (i<<1)) continue;
Have[++cont]=i;
if (i==0) continue;
int a=i,b=n;
while (A/2)
{
if (a%2)
{
for (int k=1;k<=n;k++)
{
SUM[K][CONT]+=NUM[K][B];
}
}
a/=2;
b--;
}
for (int k=1;k<=n;k++)
SUM[K][CONT]+=NUM[K][B];
}
return 0;
}
int max (int a,int b)
{
Return a>b?a:b;
}
int main ()
{
Char str[500];
int i,j;
while (gets (str))
{
int Len=strlen (str);
int t=0;
for (i=0,j=0;i<=len;i++)
{
if (str[i]== ' | | | I==len)
{
t++;
num[1][++j]=str[i-1]-' 0 ' + (str[i-2]-' 0 ') *10;
}
}
for (i=2;i<=t;i++)
for (j=1;j<=t;j++)
scanf ("%d", &num[i][j]);
n=t;
Deal ();
int dp[20][1<<n];
Memset (Dp,0,sizeof (DP));
for (i=0;i<=cont;i++)
{
Dp[1][i]+=sum[1][i];
}
for (i=2;i<=n;i++)
{
for (j=1;j<=cont;j++)
{
for (int k=1;k<=cont;k++)
{
if (Have[j]&have[k]) continue;
if (have[j]& (have[k]<<1)) continue;
if (have[j]& (have[k]>>1)) continue;
Dp[i][j]=max (Dp[i][j],dp[i-1][k]+sum[i][j]);
}
}
}
int max=0;
for (i=1;i<=n;i++)
for (j=1;j<=cont;j++)
if (Dp[i][j]>max) max=dp[i][j];
printf ("%d\n", Max);
GetChar ();
GetChar ();
}
return 0;
}
HDU 2167 State Compression DP