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. BFS-hdu-4101-Ali and Baba

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4101 题目大意: 给一个矩阵,0表示空的可走,-1宝藏的位置(只有一个),其余的正整数表示该位置石头 ...

  2. 栈的链式存储 - API实现

    基本概念 其它概念详情參看前一篇博文:栈的顺序存储 - 设计与实现 - API实现 这里也是运用了链表的链式存储API高速实现了栈的API. 代码: // linkstack.h // 链式存储栈的A ...

  3. webservice传递特殊字符时的解决的方法

    webservice soap报文是xml格式交互的,当中针对特殊字符传递无法解析,导致数据处理失败. 解决的方法例如以下: 1.在发送报文之前,针对报文进行base64转码,转义后避免报文中含有特殊 ...

  4. mysqldump 定时任务 执行后备份的文件为空

    #!/bin/bash mysql_host="127.0.0.1" mysql_user="root" mysql_passwd="******** ...

  5. 重复记录(duplicate records)相关运营数据

    MySQL 中查找反复数据,删除反复数据 创建表和測试数据 /* 表结构 */ DROPTABLEIFEXISTS `t1`; CREATETABLEIFNOTEXISTS `t1`( `id` IN ...

  6. Json字符串与字典互转

    #pragma mark 转换json字符串 +(NSString *)toJSON:(id)aParam { NSData   *jsonData=[NSJSONSerialization data ...

  7. gamit10.6问题汇总

    1.在处理精密星历时,提示:old version of file not supported (name svnav.dat) 解决办法:在gamit10.5中不会出现这个问题,10.6中的官方文档 ...

  8. python 学习笔记(二)两种方式实现第一个python程序

    在交互模式下: 如果要让Python打印出指定的文字,可以用print语句,然后把希望打印的文字用单引号或者双引号括起来,但不能混用单引号和双引号: >>> print 'hello ...

  9. require.js优化器

    项目发布前,require.js优化器可以合并require.js各个模块. 官网: http://requirejs.org/docs/optimization.html 安装 npm instal ...

  10. fiddler了解

    常常听到有人会所抓包什么的,自己电脑上有一段fiddler软件,但是一直没有使用,因为不了解.今天终于看视频,看博客,大致了解了fiddler这个软件,看着是非常强大啊.那么fiddler到底是什么, ...