Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

暴力枚举900+MS水过。。。

Posted by wiseking at 2009-11-24 12:39:47 on Problem 2531
#include <iostream>
  using namespace std;
  int n,a[21][21],pow[25],ans;
int main(){
  //freopen("pku2531.in","r",stdin);freopen("pku2531.out","w",stdout);
  scanf("%d\n",&n);
  int i,j,k,zt,all;
  pow[1]=1;
  for(i=2;i<=23;i++)pow[i]=pow[i-1]*2;
  for(i=1;i<=n;i++)
  for(j=1;j<=n;j++)scanf("%d",&a[i][j]);
  all=pow[n]-1;ans=0;
  for(zt=1;zt<=all;zt++){
    k=0;
    for(i=1;i<=n;i++)
    if((pow[i]&zt)>0)
    for(j=1;j<=n;j++)
    if((pow[j]&zt)==0)
    k+=a[i][j];
    if(k>ans)ans=k;
    };
  cout<<ans<<endl;
  return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator