poj 2531
来源:互联网 发布:知识产权 淘宝 编辑:程序博客网 时间:2024/03/29 19:13
Network Saboteur
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 9101 Accepted: 4259
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).
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 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
30 50 3050 0 4030 40 0
Sample Output
90
Source
Northeastern Europe 2002, Far-Eastern Subregion
题目意思是要把n个点随机分成两组,求一组中每个点到另外一组中每个点的距离和的最大值。
枚举每个分组情况,计算就行了。
AC代码:
#include<iostream>#include<vector>using namespace std;int a[30][30];vector <int> v1;vector <int> v2;int main(){ int n; while(cin>>n){ for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>a[i][j]; int ans=0; for(int k=1;k<(1<<n)-1;k++){ //分组情况为 1000..0——1111..0 其中0为一组,1为另一组。 if(!v1.empty()) v1.clear(); if(!v2.empty()) v2.clear(); int tmp=k; for(int i=1;i<=n;i++){ if(tmp&1) v1.push_back(i); //把1组的点保存在v1中 else v2.push_back(i); //把0组的点保存在v2中 tmp=tmp>>1; } int s=0; for(int i=0;i<v1.size();i++) //求出1组的点到0组的点的距离和 for(int j=0;j<v2.size();j++) s+=a[v1[i]][v2[j]]; if(s>ans) ans=s; } cout<<ans<<endl; } return 0;}
0 0
- poj 2531
- POJ 2531
- POJ 2531
- poj 2531
- POJ 2531
- POJ 2531
- poj-2531
- poj 2531
- poj 2531
- poj - 2531
- poj 2531
- POJ-2531
- POJ 2531(随机化思想)
- poj 2531 Network Saboteur
- Poj 2531 Network Saboteur
- POJ 2531 Network Saboteur
- POJ 2531 Network Saboteur
- POJ 2531 (DFS+剪枝)
- 最短路径Ⅰ—Dijkstra算法
- Java多态
- JSP基础语法(章节摘要)
- 1407282112-hd-Max Num.cpp
- 集合(TreeMap练习)
- poj 2531
- C++与C添加标准库头文件的形式
- Jquery 分页
- 集合(TreeMap练习-字母出现的次数)
- POJ - 1135 Domino Effect (最短路 Dijkstra)
- IE6的3像素BUG
- zoj 3299 概率dp
- Web MVC简介
- POJ 1724 ROADS (搜索+剪枝)