Network Saboteur

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

题目大意:

    把一个图用一条直线隔成两部分,求被这条直线相交的边的权值和的最大值。

解题思路:

    图论的无向完全图的最大割问题。

    先建立两个集合,一个集合包含全部的点,另一个为空集。

    此时的权值为0。

    随机选取一个点,将它从所在的集合挪到另外一个集合中。

    eg:

    当前状态的权值和为sum,将3号点,从集合1中挪到集合2中。

    则权值和的变化为

    sum+=edge[3][i],i表示在集合1中的点。

    sum-=edge[3][j],j表示在集合2中的点,不包括3号点。

    每进行一次变化,就会有新的sum产生,保存sum的最大值即可。

    (随机选择100W次后过得,随机次数越多,越可能产生标准答案,但要注意时间)

Code:

 /*************************************************************************
> File Name: poj2531.cpp
> Author: Enumz
> Mail: 369372123@qq.com
> Created Time: 2014年10月27日 星期一 19时08分08秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<time.h>
#include<climits>
#define MAXN 100000
using namespace std;
void init()
{
srand(time(NULL));
}
int edge[][];
int main()
{
init();
int N;
while (cin>>N)
{
memset(edge,,sizeof(edge));
for (int i=;i<=N;i++)
for (int j=;j<=N;j++)
cin>>edge[i][j];
int times=;
bool gather[];
int ret=,max=;
memset(gather,,sizeof(gather));
while (times--)
{
int tmp=rand()%N+;
gather[tmp]=!gather[tmp];
for (int i=;i<=N;i++)
{
if (gather[i]!=gather[tmp])
ret+=edge[i][tmp];
if (gather[i]==gather[tmp]&&i!=tmp)
ret-=edge[i][tmp];
}
max=max>ret?max:ret;
}
cout<<max<<endl;
}
return ;
}

    

    

POJ2531——Network Saboteur(随机化算法水一发)的更多相关文章

  1. poj2531 Network Saboteur

    Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11122   Accepted: 5372 ...

  2. PKU 2531 Network Saboteur(dfs+剪枝||随机化算法)

    题目大意:原题链接 给定n个节点,任意两个节点之间有权值,把这n个节点分成A,B两个集合,使得A集合中的每一节点与B集合中的每一节点两两结合(即有|A|*|B|种结合方式)权值之和最大. 标记:A集合 ...

  3. Network Saboteur(搜索)

    Network Saboteur POJ2531 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10351   Accept ...

  4. POJ 矩阵相乘 (随机化算法-舍伍德(Sherwood))

    周三的算法课,主要讲了随机化算法,介绍了拉斯维加斯算法,简单的理解了为什么要用随机化算法,随机化算法有什么好处. 在处理8皇后问题的时候,穷举法是最费时的,回朔比穷举好点,而当数据量比较大的时候,如1 ...

  5. Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏

    Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...

  6. POJ3318--Matrix Multiplication 随机化算法

    Description You are given three n × n matrices A, B and C. Does the equation A × B = C hold true? In ...

  7. CSU-ACM2016暑假集训训练2-DFS(C - Network Saboteur)

    C - Network Saboteur Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu ...

  8. 2018.09.14 codeforces364D(随机化算法)

    传送门 根据国家集训队2014论文集中胡泽聪的随机化算法可以通过这道题. 对于每个数,它有12" role="presentation" style="posi ...

  9. PKU 3318 Matrix Multiplication(随机化算法||状态压缩)

    题目大意:原题链接 给定三个n*n的矩阵A,B,C,验证A*B=C是否成立. 所有解法中因为只测试一组数据,因此没有使用memset清零 Hint中给的傻乎乎的TLE版本: #include<c ...

随机推荐

  1. poj 1659 Frogs' Neighborhood Havel-Hakimi定理 可简单图定理

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098136.html 给定一个非负整数序列$D=\{d_1,d_2,...d_n\}$,若存 ...

  2. apache重写

    ---- 本文旨在提供如何用Apache重写规则来解决一些常见的URL重写方法的问题,通过常见的实例给用户一些使用重写规则的基本方法和线索. 一.为什么需要用重写规则 ---- 网站的生命在于不断地进 ...

  3. 【转】DataGridView绑定数据源的几种方式

    第一种:DataSet ds=new DataSet (); this.dataGridView1.DataSource=ds.Table[0]; 第二种:DataTable dt=new DataT ...

  4. MongoDB的安全性

    上篇文章介绍Mongo启动了,一般数据库启动,下面的操作就是登录数据库了,之前测试数据库是否正常安装的时候也登录过数据库,现在回想一下,好像连用户名和密码都没有输入,找几篇帖子来探究下Mongodb的 ...

  5. 使用Dreamweaver批量删除PHP项目中的单行注释和多行注释

    1.删除单行注释 打开Dreamweaver的查找工具,选择正则替换如图: 里面的//.*是正则匹配单行注释的表达式   2.删除多行注释 同样用正则查找匹配,直接上图咯:  其中正则表达式为/\*[ ...

  6. SQL学习中(序)

    从校园中走出来已经两年多了,从最初的企业建站到现在的BPM流程开发,深深的感觉到自己底子很差,因此在园子里记录一下学过的知识,以此自勉. 废话到此结束,今天就先来看一下CREATE CHEMA 语句. ...

  7. AOP和IOC个人理解

    14:18 2014/5/5 IOC inversion of control 控制反转  将new对象的权力由调用者转移到spring容器(即xml文件),Struts2与Spring整合(scop ...

  8. Netty 4.0 demo

    netty是一个异步,事件驱动的网络编程框架&工具,使用netty,可以快速开发从可维护,高性能的协议服务和客户端应用.是一个继mina之后,一个非常受欢迎的nio网络框架 netty4.x和 ...

  9. 高性能图文混排框架,构架顺滑的iOS应用-b

    About GallopGallop是一个功能强大.性能优秀的图文混排框架. Features主要用于解决以下需求: 滚动列表的性能优化.Gallop使用异步绘制.视图层级合并.观察mainRunlo ...

  10. Notepad++ 书签

      Notepad++,有一个书签功能,指定书签是Ctrl+F2,在书签之间移动是按F2来切换,这个可以在几个想查看的数据之间进行快速切换,所以看起来就很方便.