2985ms AC。
以下是我的代码:
/*
* Author: lee1r
* Created Time: 2011/8/6 10:45:18
* File Name: poj2531.cpp
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#define L(x) ((x)<<1)
#define R(x) (((x)<<1)+1)
#define Half(x) ((x)>>1)
#define lowbit(x) ((x)&(-(x)))
using namespace std;
const int kInf(0x7f7f7f7f);
const double kEps(1e-8);
typedef long long int64;
typedef unsigned long long uint64;
const int kMaxn(27);
int n,g[kMaxn][kMaxn];
bool d[kMaxn];
int64 ans;
void dfs(int depth)
{
if(depth>n)
{
int now(0);
for(int i=2;i<=n;i++)
for(int j=1;j<i;j++)
if(d[i]==!d[j])
now+=g[i][j];
if(ans<now)
ans=now;
return;
}
d[depth]=true;
dfs(depth+1);
d[depth]=false;
dfs(depth+1);
}
int main()
{
//freopen("data.in","r",stdin);
while(scanf("%d",&n)==1)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
scanf("%d",&g[i][j]);
ans=0;
memset(d,false,sizeof(d));
dfs(1);
cout<<ans<<endl;
}
return 0;
}
posted on 2011-08-06 11:00
lee1r 阅读(547)
评论(0) 编辑 收藏 引用 所属分类:
题目分类:搜索