Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
就一个剪枝。157MS。应该是数据太弱#include <stdio.h> #include <string.h> int used[22],c[22][22],n,max,k; void DFS(int l,int cnt,int sum) { if(cnt > k) return; if(l > n) return; used[l] = 1; int sum1; sum1 = sum; for(int i = 1;i <= n;i++) { if(!used[i]) sum1 += c[i][l]; else sum1 -= c[i][l]; } if(sum1 > max) max = sum1; DFS(l+1,cnt+1,sum1); used[l] = 0; DFS(l+1,cnt,sum); } int main() { while(scanf("%d",&n) != EOF) { for(int i = 1;i <= n;i++) for(int j = 1;j <= n;j++) scanf("%d",&c[i][j]); max = 0; memset(used,0,sizeof(used)); k = n >> 1; DFS(1,1,0); printf("%d\n",max); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator