标签:
题意:
#include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <string> #include <cctype> #include <complex> #include <cassert> #include <utility> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> using namespace std; typedef pair<int,int> PII; typedef long long ll; #define lson l,m,rt<<1 #define pi acos(-1.0) #define rson m+1,r,rt<<11 #define All 1,N,1 #define read freopen("in.txt", "r", stdin) const ll INFll = 0x3f3f3f3f3f3f3f3fLL; const int INF= 0x7ffffff; const int mod = 1000000007; int n,now[20001],total[20001],a[20][20]; int nnum,par[20001],dp[20001],dp1[20001]; void state(int i,int k,int s,int sum){ if(k>=n){ now[++nnum]=s; total[nnum]=sum; return; } state(i,k+2,s|(1<<k),sum+a[i][k]); state(i,k+1,s,sum); } void solve(){ for(int i=0;i<n;++i){ nnum=0; state(i,0,0,0); memset(dp,0,sizeof(dp)); for(int j=1;j<=nnum;++j) for(int l=1;l<=nnum;++l) if((now[j]&now[l])==0){ dp[j]=max(dp[j],dp1[l]+total[j]); } for(int l=1;l<=nnum;++l){ dp1[l]=dp[l]; } } int maxv=-1; for(int i=1;i<=nnum;++i){ maxv=max(maxv,dp1[i]); } printf("%d\n",maxv); } int main() { while(~scanf("%d",&n)){ for(int i=0;i<n;++i) for(int j=0;j<n;++j) scanf("%d",&a[i][j]); memset(dp1,0,sizeof(dp1)); solve(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zsf123/p/4674701.html