Network Saboteur

Time Limit: 2000MS Memory Limit: 65536K

Total Submissions: 10147 Accepted: 4849

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

刚开始看的时候以为是Dp或者是图论,后来查看题解突然明白自己还是没有理解什么是dfs,dfs就是一种暴力,对于这个题中的每一个点都有两个选择,和0一个集合还是不是一个集合,至于sum为什么能记录两个集合之间的距离,自己画个图就会明白

#include <map>
#include <list>
#include <climits>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define eps 1e-9
#define LL unsigned long long
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define CRR fclose(stdin)
#define CWW fclose(stdout)
#define RR freopen("input.txt","r",stdin)
#define WW freopen("output.txt","w",stdout) const int Max = 10010; int Map[25][25]; bool vis[25]; int n; int MM; void DFS(int s,int sum)
{
vis[s]=true;
for(int i=0;i<n;i++)
{
if(vis[i])//如果是同一个集合,之间的距离会为0;
{
sum-=Map[s][i];
}
else
{
sum+=Map[s][i];
}
}
MM = max(MM,sum);//找最大值
for(int i=s+1;i<n;i++)
{
vis[i]=true;
DFS(i,sum);
vis[i]=false;
}
} int main()
{
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
scanf("%d",&Map[i][j]);
}
}
MM=0;
DFS(0,0);
printf("%d\n",MM);
} return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏的更多相关文章

  1. 滑雪 分类: POJ 2015-07-23 19:48 9人阅读 评论(0) 收藏

    滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 83276 Accepted: 31159 Description Mich ...

  2. 1.PHP站内搜索 分类: PHP开发实例 2015-07-31 22:48 4人阅读 评论(0) 收藏

    PHP站内搜索:多关键字.加亮显示 1.SQL语句中的模糊查找 $sql = "SELECT * FROM `message` WHERE `content`like '%$k[0]%' a ...

  3. A Plug for UNIX 分类: POJ 图论 函数 2015-08-10 14:18 2人阅读 评论(0) 收藏

    A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14786 Accepted: 4994 Desc ...

  4. 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏

    Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...

  5. OC基础:类的扩展.协议 分类: ios学习 OC 2015-06-22 19:22 34人阅读 评论(0) 收藏

    //再设计一个类的时候,有些方法需要对外公开(接口),有些仅供内部使用. 类的扩展:为类添加新的特征(属性)或者方法 对已知类: 1.直接添加 2.继承(在其子类中添加实例变量和方法) 3.使用ext ...

  6. android开发之this.finish()的使用 分类: android 学习笔记 2015-07-18 19:05 30人阅读 评论(0) 收藏

    在一个Activity用完之后应该将之finish掉,但是,之前在学校里自己摸索着开发时并没有太注意这个问题,因为activity无论是否finish掉对功能的影响貌似都不是那么明显(这是读书时候的观 ...

  7. 修改android应用包名 分类: android 学习笔记 2015-07-16 22:48 4人阅读 评论(0) 收藏

    由于项目需要,要修改已经开发好的应用包名,这本身很简单,但是如果你没找到门道,可能会白白浪费许多时间. 修改包名有三个地方要改,这三个地方的修改一定要按顺序来,否则你可能会遇到许多不必要的麻烦. 1. ...

  8. UI基础:事件.响应链 分类: iOS学习-UI 2015-07-03 19:51 1人阅读 评论(0) 收藏

    UIEvent:事件,是由硬件捕捉的一个代表用户操作操作设备的对象. 事件分三类:触摸事件.晃动事件.远程控制事件. 触摸事件:用户通过触摸设备屏幕操作对象,.输入数据.支持多点触摸,包含1个到多个触 ...

  9. UI基础:UILabel.UIFont 分类: iOS学习-UI 2015-07-01 19:38 107人阅读 评论(0) 收藏

    UILabel:标签 继承自UIView ,在UIView基础上扩充了显示文本的功能.(文本框) UILabel的使用步骤 1.创建控件 UILabel *aLabel=[[UILabel alloc ...

随机推荐

  1. UITabBarController底层实现

    1.首先要了解:任何控制器,都能添加子控制器      UIViewController里面有一个方法:     - (void)addChildViewController:(UIViewContr ...

  2. Swift实战-豆瓣电台(四)歌曲列表的展现

    观看地址 http://v.youku.com/v_show/id_XNzMwNDE0OTA4.html 这节的主要内容是如何利用cell展现获取到的数据. 首先申明两个数组来储存我们获取到的数据 v ...

  3. Python和Ruby抓取网页时的中文乱码问题(在Eclipse和Apatana Studio下均是这种解决方法

    Python抓取中文网页乱码 :Eclipse+pydev2.2+python2.7  :Apatana Studio3+ pydev2.2+python2.7      run时设置 run--&g ...

  4. 自定义FragmentTabHost--实现View重复加载问题

    1,接着上篇的Fragment+FragmentTabHost搭建简单的底部功能切换框架,效果如下: 结果在项目中用到的时候发现Fragment+FragmentTabHost实现的时候每一次切换底部 ...

  5. RMAN基础知识补充

    一.FORMAT字符串替代变量 使用FORMAT参数时可使用的各种替换变量,如下: %c :备份片的拷贝数(从1开始编号): %d :数据库名称: %D :位于该月中的天数 (DD): %M :位于该 ...

  6. Logic and Fault simulation

    fault simulation是指对fault circuit的simulation,来locate manufacturing defects并且进行fault diagnosis. logic ...

  7. 9. 星际争霸之php设计模式--代理模式

    题记==============================================================================本php设计模式专辑来源于博客(jymo ...

  8. php防止刷新(流量攻击)的一段代码

    <?php//查询禁止IP$ip =$_SERVER['REMOTE_ADDR'];$fileht=".htaccess2";if(!file_exists($fileht) ...

  9. :eq(index)

    匹配一个给定索引值的元素 从 0 开始计数 查找第二行 HTML 代码: <table> <tr><td>Header 1</td></tr> ...

  10. pybot/robot命令参数说明

    Robot Framework -- A generic test automation framework Version: 3.0 (Python 3.4.0 on win32) Usage: r ...