注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

zjushuiping

追求的只是心中的那一份宁静!

 
 
 

日志

 
 

POJ2531  

2010-08-17 16:03:08|  分类: ACM/ICPC |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
Network Saboteur
Time Limit: 2000MS
Memory Limit: 65536K
Total Submissions: 4515
Accepted: 1889

Description

A university network is composed of N computers. System administrators gathered information on the traffic between nodes, and carefully divided the network into two subnetworks in order to minimize traffic between parts.
A disgruntled computer science student Vasya, after being expelled from the university, decided to have his revenge. He hacked into the university network and decided to reassign computers to maximize the traffic between two subnetworks.
Unfortunately, he found that calculating such worst subdivision is one of those problems he, being a student, failed to solve. So he asks you, a more successful CS student, to help him.
The traffic data are given in the form of matrix C, where Cij is the amount of data sent between ith and jth nodes (Cij = Cji, Cii = 0). The goal is to divide the network nodes into the two disjointed subsets A and B so as to maximize the sum ∑Cij (i∈A,j∈B).

Input

The first line of input contains a number of nodes N (2 <= N <= 20). The following N lines, containing N space-separated integers each, represent the traffic matrix C (0 <= Cij <= 10000).
Output file must contain a single integer -- the maximum traffic between the subnetworks.

Output

Output must contain a single integer -- the maximum traffic between the subnetworks.

Sample Input

3
0 50 30
50 0 40
30 40 0

Sample Output

90

Source

Northeastern Europe 2002, Far-Eastern Subregion

#include <cstdlib>
#include <iostream>
#include <string.h>
#include <cstdio>
using namespace std;
int data[21][21];
int a[21];
int mount=0;

int n;
int dfs(int s,int num)
{int i,j;

if(num==0)
{         int sum=0;
          for(i=1;i<=n;i++)
          {if(a[i]==0)
           continue;
          
           for(j=1;j<=n;j++)
           {if(a[j])
            continue;
            sum+=data[i][j];
           
           }
          }
         
          if(sum>mount)
          mount=sum;
          return 1;
}

for(i=s;i<=n;i++)
{
                 if(a[i])
                 continue;
                 a[i]=1;
                 dfs(i+1,num-1);
                 a[i]=0;
   
}

return 0;
}



int main(int argc, char *argv[])
{
cin>>n;
int i,j;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
cin>>data[i][j];
mount=0;

memset(a,0,sizeof(a));
for(i=1;i<=n/2;i++)
dfs(1,i);

cout<<mount<<endl;
                  


    system("PAUSE");
    return EXIT_SUCCESS;
}


  评论这张
 
阅读(784)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017