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 |
暴力枚举居然也能过 无语 贴一下代码#include <iostream> #include <algorithm> using namespace std; int n; int a[8][8]; int ans; void rota(int i) { int temp; temp=a[i][n-1]; int j; for(j=n-2;j>=0;j--) a[i][j+1]=a[i][j]; a[i][0]=temp; } void solve(int i) { if (i>n-1) { int sum; int max; int j; max=0x80000000; for (j=0;j<n;j++) { sum=0; for (i=0;i<n;i++) { sum+=a[i][j]; } if (sum>max) { max=sum; } } if(ans>max) ans=max; } else { int k; for(k=0;k<n;k++) { rota(i); solve(i+1); } } } int main(void) { int i,j; while(cin>>n && n!=-1) { for (i=0;i<n;i++) { for (j=0;j<n;j++) { cin>>a[i][j]; } } ans=0x7fffffff; solve(0); cout<<ans<<endl; } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator