poj2531:http://poj.org/problem?id=2531

题意:给你一个图,图中点之间会有边权,现在问题是把图分成两部分,使得两部分之间边权之和最大。
题解:一开始比知道怎么办,想用搜索,但是20的范围,觉得范围有点大,所以没敢打,最后还是试了试结果竟然过了。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[],b[];//记录图中的两部分
int num1,num2;
int counts,minn;
int vis[];
int n;
int g[][];
void DFS(int x){//对于一个点来说,要么属于A部分,要么属于B部分,所以分两部分进行DFS
if(x==n+){//到了底部,就开始统计边权之和,然后比较,看看是否需要更新最大值。
memset(a,,sizeof(a));
memset(b,,sizeof(b));
num1=num2=;
for(int i=;i<=n;i++){
if(vis[i])
a[++num1]=i;
else
b[++num2]=i;
}
counts=;
for(int i=;i<=num1;i++)
for(int j=;j<=num2;j++){
if(g[a[i]][b[j]])
counts+=g[a[i]][b[j]];
}
if(counts>minn)
minn=counts;
return;
}
vis[x]=;
DFS(x+);
vis[x]=;
DFS(x+);
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
cin>>g[i][j];
minn=;
DFS();
printf("%d\n",minn);
}

Network Saboteur的更多相关文章

  1. poj2531 Network Saboteur

    Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11122   Accepted: 5372 ...

  2. Network Saboteur 分类: 搜索 POJ 2015-08-09 19:48 7人阅读 评论(0) 收藏

    Network Saboteur Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10147 Accepted: 4849 Des ...

  3. POJ2531——Network Saboteur(随机化算法水一发)

    Network Saboteur DescriptionA university network is composed of N computers. System administrators g ...

  4. CSU-ACM2016暑假集训训练2-DFS(C - Network Saboteur)

    C - Network Saboteur Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu ...

  5. Network Saboteur(搜索)

    Network Saboteur POJ2531 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10351   Accept ...

  6. C——Network Saboteur (POJ2531)

    题目: A university network is composed of N computers. System administrators gathered information on t ...

  7. Network Saboteur (深搜递归思想的特殊使用)

    个人心得:对于深搜的使用还是不到位,对于递归的含义还是不太清楚!本来想着用深搜构成一个排列,然后从一到n分割成俩个数组,然后后面发现根本实现不了,思路太混乱.后来借鉴了网上的思想,发现用数组来标志,当 ...

  8. Network Saboteur POJ 2531 回溯搜索

    Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12886   Accepted: 6187 Description A un ...

  9. POJ-2561 Network Saboteur(DFS)

    题目: A university network is composed of N computers. System administrators gathered information on t ...

  10. Network Saboteur (DFS)

    题目: A university network is composed of N computers. System administrators gathered information on t ...

随机推荐

  1. 未能从程序集“WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35“ 中加载“System.Windows.SplashSceen”

    通过添加windowsbase.dll,可以解决这个问题,你可以在自己的电脑上找到这个文件,地址是:C:\Program Files\Reference Assemblies\Microsoft\Fr ...

  2. Delphi下实现全屏快速找图找色

    前言 最近有好几个朋友都在问我找图找色的问题,奇怪?于是乎写了一个专门用于找图找色的单元文件“BitmapData.pas”.在这个单元文件中我实现了从文件中导入位图.屏幕截图.鼠标指针截图.在图片上 ...

  3. [置顶] 基于视频采集卡驱动的错误修改CX26828

    基于视频采集卡驱动的错误修改CX26828 1. 设置root密码 command:sudo passwd root 2.查看系统状态 输入命令:lsmod root@ubuntu:/home/yu# ...

  4. Android 判断数据库中是否存在某个表

    public boolean tabIsExist(String tabName){ boolean result = false; if(tabName == null){ return false ...

  5. 怎样让HTML5调用手机摄像头拍照——实践就是一切

    原文:怎样让HTML5调用手机摄像头拍照--实践就是一切 NanShan 小编将思路提供给了大家.学编程最重要的是实践,我这尽管有完好的代码,可是希望大家都能够自己写出属于自己的代码 HTML5 Th ...

  6. linux下mysql配置文件my.cnf详解

    basedir = path 使用给定目录作为根目录(安装目录). character-sets-dir = path 给出存放着字符集的目录. datadir = path 从给定目录读取数据库文件 ...

  7. tcmalloc资料

    1. 确定dylib在max os是可以成功的. http://lists.apple.com/archives/perfoptimization-dev/2008/Dec/msg00002.html ...

  8. 【Android】android镜像翻转

    Android镜像翻转指的是将屏幕进行水平的翻转,达到所有内容显示都会反向的效果,就像是在镜子中看到的界面一样.这种应用的使用场景相对比较受限,主要用在一些需要使用Android手机界面进行镜面投影的 ...

  9. StringHelper类,内容截取,特别适合资讯展示列表

    public class StringHelper    {        /// <summary>        /// 截字符串        /// </summary> ...

  10. Use StringBuilder instead of String as possible as you can.

    If you are care a littile about the time your algorithm cost,you should notice that,you my use Strin ...