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. 20172306 《Java程序设计与数据结构》第七周学习总结

    20172306<Java程序设计>第七周学习总结 教材学习内容总结 这一章的标题是继承.主要学习了有关继承的相关知识.其中在这五节中,我学到了以下几点: 1.继承主要表达的是" ...

  2. 域名ping不通,ip地址ping得通

    原因:dns服务器过期,需要更换dns服务器地址

  3. Spring ApplicationContext(十)finishRefresh

    ApplicationContext(十)finishRefresh Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 经过 ...

  4. Spring Boot REST(二)源码分析

    Spring Boot REST(二)源码分析 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) SpringBoot RE ...

  5. MySQL 系列(一)安装

    MySQL 系列(一)安装 以 Centos7 下安装 MySQL 5.6 为例. 一.环境准备 (1) 下载 下载地址: https://dev.mysql.com/get/Downloads/My ...

  6. Previous Permutation

    Similar to next permutation, the steps as follow: 1) Find k in the increasing suffix such that nums[ ...

  7. Tomcat优化方案

    摘自网络: 调优方案分类: 1,外部环境调优 2,自身调优 --------------------------------------------------- 外部环境调优: 1, JAVA虚拟机 ...

  8. tomcat项目中配置数据库连接池

    1. 在项目中新建context.xml文件,不要在tomcat服务器的目录中修改context.xml(会对整个服务器生效)..   在web项目的META-INF中存放context.xml 2. ...

  9. TOMCAT内存溢出及大小调整的实现方法

    一.tomcat内存设置问题 收藏 在使用Java程序从数据库中查询大量的数据或是应用服务器(如tomcat.jboss,weblogic)加载jar包时会出现java.lang.OutOfMemor ...

  10. 2019.01.23 ural1519 Formula 1(轮廓线dp)

    传送门 轮廓线dpdpdp模板题. 题意简述:给一个放有障碍的网格图,问有多少种方法能使所有非障碍格子都在同一条哈密顿回路上面. 考虑用括号序列的写法来状压这个轮廓线. 用000表示没有插头,111表 ...