C - Network Saboteur

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

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

解题思路:题目大意:给定一个邻接矩阵,要求将顶点分为A,B两个集合,使得A集合中的所有顶点到B集合所有顶点的距离之和为最大。
首先两个集合的表示用一个一维数组A[],其中A[i]=1,表示节点i在集合A中,为0则在集合B中。
二位数组C[][]存储邻接矩阵,
由于每一个数字有两种选择0和1,结构适用深度优先:从第一个数开始A[0]=1(假设0号顶点一定在集合A中),
对0来说第2个顶点有两种情况,依次类推,结构就出来了。递归出口就是到达第n-1号顶点。
求和用两个for循环加上对存在集合的判定,记录最大值,每次求和结果与最大值比较,如果更大则修改最大值。 收获感想:对深度优先有了更深刻的理解,刚开始编写的时候思路有点混乱,不知道怎么写递归,出口也搞错了,一遍遍的过程中深入理解。
#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
int A[],B[],C[][],N,sum,tp=,tp2=;
void bfs(int tp,int l);
int main()
{
memset(A,,);
//memset(B,-1,21); while(scanf("%d",&N)!=EOF){
for(int i=;i<N;i++)
for(int j=;j<N;j++)
scanf("%d",&C[i][j]);
bfs(,);
printf("%d\n",sum);
} return ;
} void bfs(int tp,int l)
{
if(tp==N||tp==-) return;
int s=;
A[tp]=l;
for(int i=;i<N;i++)
{
if(A[i]==)
for(int j=;j<N;j++)
{
if(A[j]==)
s=s+C[i][j]; }
}
if(sum<s) sum=s;
bfs(tp+,);
bfs(tp+,);
}

CSU-ACM2016暑假集训训练2-DFS(C - Network Saboteur)的更多相关文章

  1. 2016HUAS暑假集训训练题 G - Oil Deposits

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  2. 2016huasacm暑假集训训练五 H - Coins

    题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/H 题意:A有一大堆的硬币,他觉得太重了,想花掉硬币去坐的士:的士司机可以不找零,但 ...

  3. 2016huasacm暑假集训训练五 J - Max Sum

    题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/J 题意:求一段子的连续最大和,只要每个数都大于0 那么就会一直增加,所以只要和0 ...

  4. 2016huasacm暑假集训训练五 G - 湫湫系列故事——减肥记I

    题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/G 这是一个01背包的模板题 AC代码: #include<stdio.h&g ...

  5. 2016huasacm暑假集训训练五 F - Monkey Banana Problem

    题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/F 题意:求至上而下一条路径的所经过的值得和最大值,这题比赛时就出了 但当时看不懂题 ...

  6. 2016huasacm暑假集训训练五 E - What Is Your Grade?

    题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/E 题意:给做出的题目个数,5个的100分,4个的前n/2的同学95,后n/2的90 ...

  7. 2016huasacm暑假集训训练五 C-Common Subsequence

    题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/C 题意:这是一道求字符串的公共子串的最大长度的题目,用dp动态方程即可 if(a[ ...

  8. 2016huasacm暑假集训训练四 DP_B

    题目链接:http://acm.hust.edu.cn/vjudge/contest/125308#problem/M 题意:有N件物品和一个容量为V的背包.第i件物品的费用是体积c[i],价值是w[ ...

  9. 2016huasacm暑假集训训练四 数论_B

    题目链接:http://acm.hust.edu.cn/vjudge/contest/125308#problem/G 题意:求有多少x(1<=x<=n),使得gcd(x,n)>=m ...

随机推荐

  1. eclipse项目导入到Android Studio Plugin with id 'android-library' not found

    在主项目的build.gradle 中加入以下代码buildscript { repositories { mavenCentral() } dependencies { classpath 'com ...

  2. 给postfix设置黑名单

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  3. HDU 4608 I-number(模拟)

    I-number Time Limit: 5000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 The I-number of x is defined t ...

  4. sgu 101 无向图有双重边的欧拉路径

    #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> ...

  5. systemd service

    Man page systemd.unit SYSTEMD.UNIT(5) systemd.unit SYSTEMD.UNIT(5) NAME systemd.unit - Unit configur ...

  6. Eclipse安装ADT失败解决办法

    Eclipse的版本是3.5.2,配置Android的开发环境时遇到问题…… 按照Android官方文档一步步安装,到了安装Eclipse的ADT插件时,提示“requires 'org.eclips ...

  7. iOS开发——swift精讲&MVC应用实战

    MVC应用实战 iOS开发中设计模式是很重要的,其中,使用最多的就是MVC模式,今天就简单介绍一下在Swift中这么使用MVC模式来实现我们想要的功能: 模型-视图-控制器(Model-View-Co ...

  8. 父 shell,子 shell ,export 与 变量传递

    http://blog.csdn.net/dreamcoding/article/details/8519689/ http://caoruntao.iteye.com/blog/1018656

  9. 常用免费快递查询API对接案例

    现在许多电商公司和ERP都会寻找比较适用的集成快递查询接口,减少对接难度,现在整理一下常用的免费快递查询接口,并附上调用案例,如果有觉得不对的地方,望能够一起沟通探讨! 一.快递查询接口 目前有提供免 ...

  10. Bleed Brake Master Cylinder with Intelligent Tester IT2

    When the brake fluid level drops too low in the master cylinder reservoir, air bubbles can get caugh ...