<span style="font-family: tahoma, arial, sans-serif; font-size: 28px; background-color: rgb(255, 255, 255);">Description</span>
<span style="font-family: tahoma, arial, sans-serif; font-size: 28px; background-color: rgb(255, 255, 255);">Description</span>
As every one known, a football team has 11 players . Now, there is a big problem in front of the Coach Liu. The final contest is getting closer. Who is the center defense, the full back or the forward? ...... There are n wonderful players for n positions in the team and Coach Liu know everyone's abilities at different positions in matches. Assume that the team's power is the sum of the abilities of all n players according to their positions, could you help Coach Liu to find out the max power his team can get?
输入格式
The first line is an integer n(n<11). Followed by n rows. Each row has n integer (0 to 1000) which represents the abilities of one player at different positions.
输出格式
The max power.
输入样例
10 4 6 3 3 4 5 7 4 9 0 5 9 3 4 6 1 7 3 9 3 1 5 8 0 5 4 2 7 9 3 4 6 9 4 7 3 7 9 5 4 2 0 1 3 2 5 8 4 6 2 1 5 8 4 2 6 8 0 4 2 1 4 2 6 8 9 4 2 6 8 1 2 9 5 6 4 2 7 5 7 2 4 7 5 8 5 3 2 6 4 2 4 6 4 8 7 3 5 7 3
输出样例
76
回溯时注意每个变量的恢复处理,不要弄错!!!
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int maze[11][11]; int vis[11]={0}; int n,k; int res=0; void dfs(int cur,int ans) { int i,j; if(cur==n) { res=max(ans,res); return; } else { for(i=0;i<n;i++) { if(vis[i]==0) { ans+=maze[cur][i]; vis[i]=1; dfs(cur+1,ans); vis[i]=0; ans-=maze[cur][i]; } } } return; } int main() { scanf("%d",&n); memset(maze,0,sizeof(maze)); memset(vis,0,sizeof(vis)); int i,j; for(i=0;i<n;i++) { for(j=0;j<n;j++) scanf("%d",&maze[i][j]); } dfs(0,0); printf("%d\n",res); return 0; } /* 3 1 2 3 1 0 0 0 1 0 */