Network Saboteur

Time Limit: 2000 MS Memory Limit: 65536 KB

64-bit integer IO format: %I64d , %I64u Java class name: Main

[Submit] [Status] [Discuss]

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

 #include <iostream>
#include <string.h>
#include <stdio.h> using namespace std;
#define maxx 25
int map[maxx][maxx];
int set[maxx]; ///判断点是否在集合里
int ans;
int n; int dfs(int id,int sum)
{
set[id]=;
for(int i=;i<=n;i++) ///与id这个点不同的点 加入到这个边
{
if(set[i]==)
sum+=map[id][i];
else
sum-=map[id][i];
}
if(sum>ans) ///更新最大值
{
ans=sum;
}
for(int i=id+;i<=n;i++) ///搜之后的 全部的点都搜过 求最大的sum
{
dfs(i,sum);
set[i]=; ///回溯
}
} int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
scanf("%d",&map[i][j]);
}
}
memset(set,,sizeof(set));
ans=;
dfs(,);
printf("%d\n",ans);
}
return ;
}

~~~~~~~~~~~~

自我认为  根本没有剪枝   全都搜索了一遍

poj 2531 搜索剪枝的更多相关文章

  1. 搜索+剪枝——POJ 1011 Sticks

    搜索+剪枝--POJ 1011 Sticks 博客分类: 算法 非常经典的搜索题目,第一次做还是暑假集训的时候,前天又把它翻了出来 本来是想找点手感的,不想在原先思路的基础上,竟把它做出来了而且还是0 ...

  2. 【迭代博弈+搜索+剪枝】poj-1568--Find the Winning Move

    poj  1568:Find the Winning Move   [迭代博弈+搜索+剪枝] 题面省略... Input The input contains one or more test cas ...

  3. NOIP2015 斗地主(搜索+剪枝)

    4325: NOIP2015 斗地主 Time Limit: 30 Sec  Memory Limit: 1024 MBSubmit: 270  Solved: 192[Submit][Status] ...

  4. hdu 5469 Antonidas(树的分治+字符串hashOR搜索+剪枝)

    题目链接:hdu 5469 Antonidas 题意: 给你一颗树,每个节点有一个字符,现在给你一个字符串S,问你是否能在树上找到两个节点u,v,使得u到v的最短路径构成的字符串恰好为S. 题解: 这 ...

  5. hdu 5887 搜索+剪枝

    Herbs Gathering Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. hdu 5113(2014北京—搜索+剪枝)

    题意:有N*M的棋盘,用K种颜色去染,要求相邻块不能同色.已知每种颜色要染的块数,问能不能染,如果能,输出任一种染法. 最开始dfs失败了- -,优先搜索一行,搜完后进入下一列,超时.本来以为搜索不行 ...

  7. luogu 1731 搜索剪枝好题

    搜索剪枝这个东西真的是骗分利器,然鹅我这方面菜的不行,所以搜索数学dp三方面是真的应该好好训练一下 一本通的确该认真的刷嗯 #include<bits/stdc++.h> using na ...

  8. [HNOI2002]彩票 (搜索+剪枝)

    题目描述 某地发行一套彩票.彩票上写有1到M这M个自然数.彩民可以在这M个数中任意选取N个不同的数打圈.每个彩民只能买一张彩票,不同的彩民的彩票上的选择不同. 每次抽奖将抽出两个自然数X和Y.如果某人 ...

  9. luogu P3393 逃离僵尸岛-搜索剪枝+spfa

    P3393 逃离僵尸岛 题目描述 小a住的国家被僵尸侵略了!小a打算逃离到该国唯一的国际空港逃出这个国家. 该国有N个城市,城市之间有道路相连.一共有M条双向道路.保证没有自环和重边. K个城市已经被 ...

随机推荐

  1. SumatraPDF默认配置文件备份

    background color of the non-document windows, traditionally yellow MainWindowBackground = #fff200 if ...

  2. pop回到之前的某一个页面

    循环遍历 - (void)backHome:(UIButton *)button { self.navigationController.navigationBarHidden = NO; 4 Cas ...

  3. linux以16进制方式查看文件

    vim打开文件 :%!xxd  以16进制查看 :%!xxd -r  转回来

  4. libpcap 库使用(一)

    参考资料: http://www.tcpdump.org/ DESCRIPTION The Packet Capture library provides a high level interface ...

  5. js使用sessionStorage、cookie保存token

    本文是参考别人的博客写的,图片直接用的别人的 1.Token:token是客户端频繁向服务器端请求数据,服务器频繁的去数据库查询用户名和密码进行对比,判断用户名和密码正确与否,并作出相应的提示,在这样 ...

  6. mybatis 复杂传参

    1基本传参数 Public User selectUserWithCon(@param(“userName”)String  name,@param(“userArea”)String area); ...

  7. OpenSSH配置与基本使用

    SSH访问远程 SSH常见分类: telnet-远程登录协议,23/TCP 明文认证.明文传输(不安全) ssh(Secure SHell)-应用层协议,22/TCP 通讯和认证过程加密.主机认证 用 ...

  8. android-如何获得当前正在运行的activity的相关信息

    http://blog.csdn.net/centralperk/article/details/7269326 ActivityManager manager = (ActivityManager) ...

  9. get load 代理对象

    01使用session中的load方法查询数据库中的记录时,我们返回的是一个代理对象,而不是真正需要的那个对象. 02 因为代理对象的出现 才导致延迟加载. 还有采用懒加载的时候容易出现nosessi ...

  10. MongDB 配置成本地服务

    一.配置mangodb. 首先现在下来直接安装就好了, 可视化工具可以后面再安装. 在自己安装的目录下面(这个随意做好能够放一块)建立一个data文件, 再在下面建立一个db文件 在cmd中进入到Mo ...