Network Saboteur
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 10391   Accepted: 4990

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

  1. 3
  2. 0 50 30
  3. 50 0 40
  4. 30 40 0

Sample Output

  1. 90
    题意:将n个数分成两个集合,求一个集合中所有数到另一个集合所有数的最大和
  1. #include <iostream>
  2. #include <cstring>
  3. #include <string.h>
  4. #include <algorithm>
  5. #include <cstdio>
  6.  
  7. using namespace std;
  8. const int MAX = ;
  9. int a[MAX][MAX],v[MAX],b[MAX];
  10. int n,cnt,sum;
  11. void dfs(int x,int sum)
  12. {
  13. v[x] = ;
  14. for(int i = ; i <= n; i++)
  15. {
  16. if(v[i] == )
  17. sum += a[x][i];
  18. else
  19. sum -= a[x][i];
  20. }
  21. cnt = max(cnt,sum);
  22. for(int i = x + ; i <= n; i++) // 这个注意;其实可以这么想,以前求的是路径所以颠倒顺序也是一种情况,这是集合,所以颠倒顺序和原来是一种情况,所以没必要从0开始循环,0,1和1,0是一种情况
  23. {
  24. dfs(i,sum);
  25. v[i] = ;
  26. }
  27. }
  28. int main()
  29. {
  30. while(scanf("%d", &n) != EOF)
  31. {
  32. for(int i = ; i <= n; i++)
  33. {
  34. for(int j = ; j <= n; j++)
  35. {
  36. scanf("%d", &a[i][j]);
  37. }
  38. }
  39. memset(v,,sizeof(v));
  40. cnt = ;
  41. dfs(,);
  42. printf("%d\n",cnt);
  43. }
  44. return ;
  45. }

POJ2531Network Saboteur(DFS+剪枝)的更多相关文章

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

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

  2. *HDU1455 DFS剪枝

    Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  3. POJ 3009 DFS+剪枝

    POJ3009 DFS+剪枝 原题: Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16280 Acce ...

  4. poj 1724:ROADS(DFS + 剪枝)

    ROADS Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10777   Accepted: 3961 Descriptio ...

  5. DFS(剪枝) POJ 1011 Sticks

    题目传送门 /* 题意:若干小木棍,是由多条相同长度的长木棍分割而成,问最小的原来长木棍的长度: DFS剪枝:剪枝搜索的好题!TLE好几次,终于剪枝完全! 剪枝主要在4和5:4 相同长度的木棍不再搜索 ...

  6. DFS+剪枝 HDOJ 5323 Solve this interesting problem

    题目传送门 /* 题意:告诉一个区间[L,R],问根节点的n是多少 DFS+剪枝:父亲节点有四种情况:[l, r + len],[l, r + len - 1],[l - len, r],[l - l ...

  7. HDU 5952 Counting Cliques 【DFS+剪枝】 (2016ACM/ICPC亚洲区沈阳站)

    Counting Cliques Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  8. HDU 5937 Equation 【DFS+剪枝】 (2016年中国大学生程序设计竞赛(杭州))

    Equation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  9. LA 6476 Outpost Navigation (DFS+剪枝)

    题目链接 Solution DFS+剪枝 对于一个走过点k,如果有必要再走一次,那么一定是走过k后在k点的最大弹药数增加了.否则一定没有必要再走. 记录经过每个点的最大弹药数,对dfs进行剪枝. #i ...

随机推荐

  1. 5050 [JL] 他爱上了鸭蛋

    5050 [JL] 他爱上了鸭蛋  时间限制: 1 s  空间限制: 1000 KB  题目等级 : 白银 Silver 题解       题目描述 Description 小明爱上了零鸭蛋.他喜欢输 ...

  2. POJ 2406 Power Strings

    F - Power Strings Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  3. (转载)Apache下error.log文件太大的处理

    偶尔发现Apache下的错误日志非常的大,有5G多,先停止Apache服务的所有进程,最简单就是输命令:net stop apache2.4,然后删除 Apache/logs/目录下的 error.l ...

  4. [转]SIFT特征提取分析

    SIFT(Scale-invariant feature transform)是一种检测局部特征的算法,该算法通过求一幅图中的特征点(interest points,or corner points) ...

  5. GeoServer 常见问题总结

    Geoserver安装环境 Geoserver在部署发布服务时,经常会遇到如下问题,现总结如下: 1.忘记了GeoServer Web Admin Page的登陆用户名和密码怎么办? 存储位置:C:\ ...

  6. 在opencv3中实现机器学习之:利用svm(支持向量机)分类

    svm分类算法在opencv3中有了很大的变动,取消了CvSVMParams这个类,因此在参数设定上会有些改变. opencv中的svm分类代码,来源于libsvm. #include "s ...

  7. Android 编程下 Touch 事件的分发和消费机制

    Android 中与 Touch 事件相关的方法包括:dispatchTouchEvent(MotionEvent ev).onInterceptTouchEvent(MotionEvent ev). ...

  8. [CareerCup] 7.7 The Number with Only Prime Factors 只有质数因子的数字

    7.7 Design an algorithm to find the kth number such that the only prime factors are 3,5, and 7. 这道题跟 ...

  9. Arduino智能小车实践学习报告

    Arduino智能小车实践学习报告 参与人员: 20135316 王剑桥 20135312 吴汉彦 20135319 朱锂 一. 背景了解: 单片机:将中央处理单元CPU(进行运算.控制).随机存储器 ...

  10. 20145208 《Java程序设计》第8周学习总结

    20145208 <Java程序设计>第8周学习总结 教材学习内容总结 NIO与NIO2 NIO与IO的区别 IO           NIO 面向流             面向缓冲 阻 ...