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. HDOJ4261 Estimation

    一道需要用堆初始化的\(DP\) 原题链接 显然对于每一个部分,当\(b[i]\)为\(a\)对于部分的中位数时,差错最小.设\(S(x,y)\)表示\(x\sim y\)这一部分的差错. \(DP\ ...

  2. 如何让网站在百度有LOGO展示

    什么叫没有了网站logo?准确来说应该是网站索引logo,这个logo确实网站很好的一个展示窗口,我以长沙seo关键词为例,我给大家举例! 我输入长沙SEO,出来的百度索引图,原本所有我标红的框子里都 ...

  3. Luogu 2577[ZJOI2005]午餐 - 动态规划

    Solution 啊... 我太菜了唔 不看题解是不可能的, 这辈子都不可能的. 首先一个队伍中排队轮到某个人的时间是递增的, 又要加上吃饭时间, 所以只能使吃饭时间递减, 才能满足最优,于是以吃饭时 ...

  4. wait()和sleep()的区别

    wait()是Object类的方法,当一个线程执行到wait()方法时,该线程就进入到一个和该线程相关的等待池中,同时释放了对象锁(暂时失去对象锁,wait(long timeout)超时时间到后还需 ...

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

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

  6. vue脚手架搭建的具体步骤

    1.全局安装cli npm install -g vue-cli 在全局安装vue的命令行工具 2.初始化项目 vue init webpack my-project   初始化一个基于webpack ...

  7. GRADLE下运行main函数/执行测试用例

    group 'gongsibao.ged' version '1.0-SNAPSHOT' apply plugin: 'java' apply plugin: 'idea' sourceCompati ...

  8. MMS从Contacts中添加收件人显示email账号

    android系统默认代码,MMS中可以添加email地址作为收件人,但是从Contacts中选择收件人时却不显示email. 解决思路:为了降低修改量,在原来只搜索phoneNum的基础上,再做一次 ...

  9. 【转】VxWorks中高精度实时时钟的实现及C语言汇编混合编程

    最近一个项目中需要在VxWorks下使用一个高精度实时时钟,要求精度为1ms,溢 出时间大于5小时.VxWorks提供系统时钟,该时钟在操作系统启动后开始计数,精度为1个tick,可以通过tickGe ...

  10. 2018.11.02 洛谷P2831 愤怒的小鸟(状压dp)

    传送门 状压一眼题. 直接f[i]f[i]f[i]表示未选择状态为iii时的最小次数. 然后考虑现在怎么转移. 显然可以直接枚举消掉某一个点或者某两个点,复杂度O(n22n)O(n^22^n)O(n2 ...