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. Headfirst设计模式的C++实现——复合模式

    observer.h #ifndef _OBSERVER_H_ #define _OBSERVER_H_ #include <string> class Observer { public ...

  2. 【转】Windows Phone 调整屏幕亮度的简单实现

    之前看到以及其它应用都有调节屏幕亮度的功能,还以为MS有相关的API,就去MSDN找了下,但是怎么都找不到.今天突然想到做自定义MessageBox时,由于要突出弹出框部分,所以会改变LayoutRo ...

  3. Linux 通过 shell 脚本修改密码

    交互方式修改密码 1. ssh 远程到主机: 2. 切换到root账号: [一般都是切换到root进行密码修改,如果普通用户修改自己的密码,要输入原密码,然后新密码要满足复杂度才OK]: 3. pas ...

  4. Jquery操作下拉框(DropDownList)的取值赋值实现代码(王欢)

    Jquery操作下拉框(DropDownList)的取值赋值实现代码(王欢) 1. 获取选中项: 获取选中项的Value值: $('select#sel option:selected').val() ...

  5. hibernate导入大量数据时,为了避免内存中产生大量对象,在编码时注意什么,如何去除?

    Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); for ( i ...

  6. Popup window

    function createLoadingDialog() { $("#loadingDialog").dialog({ autoOpen: false, closeOnEsca ...

  7. spring-cloud-turbine

    turbine主要用于聚合hystrix的监控数据 依赖pom <dependencyManagement> <dependencies> <dependency> ...

  8. Limit参数优化MySQL查询的方法

    在做一些查询时,总希望能避免数据库引擎做全表扫描,因为全表扫描时间长,而且其中大部分扫描对客户端而言是没有意义的.那么,在mysql中有那些方式是可以避免全表扫面?除了通过使用索引列或分区等方式来进行 ...

  9. fedora 解决yumBackend.py进程CPU占用过高

    fedora启动时电脑风扇噪声巨响,检查进行发现是yumBackend.py进行占用CPU过高. yumBackend.py进行是后台检查更新,如果觉得没用可以使用工具关闭检查更新,或者修改检查周期. ...

  10. css 面试学习

    最经在学习前端的一些东西 转载于http://www.cnblogs.com/lei2007/archive/2013/08/16/3262897.html 雅虎的css前端的35条定律