题意:http://acm.hdu.edu.cn/showproblem.php?pid=1565

取不相邻的点是权值最大。

这题可以网络流做,暂时先DP一下,网络流明天学一下~~

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
int abss(int a);
int lowbit(int n);
int Del_bit_1(int n);
int maxx(int a,int b);
int minn(int a,int b);
double fabss(double a);
void swapp(int &a,int &b);
clock_t __STRAT,__END;
double __TOTALTIME;
void _MS(){__STRAT=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const double E=2.718281828;
const double PI=acos(-1.0);
//const ll INF=(1LL<<60);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; int ok_num[N];
int dp[][];
int a[][]; bool OK(int n,int x)
{
int F[];
F[]=;
for(int i=;i<=n;++i)
F[i]=(x>>(n-i))&;
for(int i=;i<n;++i)
if(F[i]&&F[i+])return ;
return ;
}
int get(int now,int state,int n)
{
int F[];
F[]=;
for(int i=;i<=n;++i)
F[i]=(state>>(n-i))&; int temp=;
for(int i=;i<=n;++i)
if(F[i])temp+=a[now][i];
return temp;
} void solve(int n)
{
int cnt=;
int tot=(<<n)-;
for(int i=;i<=tot;++i)
{
if(OK(n,i))
ok_num[++cnt]=i;
}
// cout<<cnt<<endl;
for(int i=;i<=n;++i)
for(int j=;j<=n;++j)
sc("%d",&a[i][j]);
for(int i=;i<=cnt;++i)
dp[][i]=dp[][i]=;
for(int i=;i<=n;++i)
{
for(int j=;j<=cnt;++j)
{
int temp=get(i,ok_num[j],n);
// dp[1][j]=temp;
for(int k=;k<=cnt;++k)
{
if((ok_num[j]&ok_num[k])==)
dp[][j]=maxx(dp[][j],temp+dp[][k]);
}
}
for(int j=;j<=cnt;++j)
dp[][j]=dp[][j],dp[][j]=;
}
int ans=;
for(int i=;i<=cnt;++i)
ans=maxx(ans,dp[][i]);
pr("%d\n",ans);
} int main()
{
int n;
while(~sc("%d",&n))solve(n);
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}
05-18 03:44