1 #include"iostream" 2 #include"cstring" 3 using namespace std; 4 #define MAXN 20+5 5 int C[MAXN][MAXN]; 6 int vis[MAXN]; 7 int N; 8 int ans; 9 void dfs(int id,int data){ 10 vis[id]=1; 11 int tmp=data; 12 for(int i=1;i<=N;i++){ 13 if(vis[i]==0) 14 tmp+=C[i][id]; 15 else 16 tmp-=C[i][id]; 17 } 18 if(ans<tmp) 19 ans=tmp; 20 for(int i=id+1;i<=N;i++){ 21 if(tmp>data){ 22 dfs(i,tmp); 23 vis[i]=0; 24 } 25 } 26 } 27 int main(){ 28 cin>>N; 29 for(int i=1;i<=N;i++) 30 for(int j=1;j<=N;j++) 31 cin>>C[i][j]; 32 memset(vis,0,sizeof(vis)); 33 ans=0; 34 dfs(1,0); 35 cout<<ans<<endl; 36 return 0; 37 38 }
时间: 2024-10-11 02:57:47