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

Re:赞一个

Posted by liuyuhong at 2016-01-24 18:22:13 on Problem 2531
In Reply To:位运算……怎么147ms? Posted by:lmy199433 at 2011-10-18 21:43:46
> #include<stdio.h>
> const int N=21;
> int n,map[N][N],ans,f[1<<20];
> bool v[1<<20];
> inline bool find(int x,int s)
> {return s>>(x-1)&1;}
> inline int max(int a,int b)
> {if(a>b)return a;return b;}
> int main()
> {
>   //freopen("poj2531.in","r",stdin);
>   //freopen("poj2531.out","w",stdout);
>   scanf("%d",&n);
>   for(int i=1;i<=n;i++)
>     for(int j=1;j<=n;j++)
>     scanf("%d",&map[i][j]);
>   int s=(1<<n)-1;
>   for(int i=1;i<s;i++)
>   if(!v[i])
>   {
>     v[i]=1;
>     v[i^s]=1;
>     int j=1;
>     for(;j<=n;j++)
>       if(find(j,i))
>       break;
>     f[i]=f[i-(-i&i)];
>     for(int k=1;k<=n;k++)
>       if(find(k,i-(-i&i)))
>       f[i]-=map[j][k];
>       else f[i]+=map[j][k];
>     f[i^s]=f[i];
>     ans=max(ans,f[i]);
>   }
>   printf("%d\n",ans);
> }
>     
>     
>   

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