poj-2531 Network Saboteur DFS
来源:互联网 发布:淘宝上好用的瘦身产品 编辑:程序博客网 时间:2024/05/12 04:50
题意:有n个点,把这些点分别放到两个集合里,在两个集合的每个点之间都会有权值,求最大的两集合间权值和。如果用图论解释的话,就是求两个完全图之间最大割边和。
思路:DFS枚举所有集合分配的情况。累加两集合间边的权值。找出最大和。
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cstdlib>#define INF 0x3f3f3f3f#define mod 1000000007using namespace std;int map[50][50],n;int vis[50];int ans;void DFS(int id,int data){ vis[id]=1; int sum=data,i; for (i=1;i<=n;i++) { if(!vis[i]) sum += map[i][id]; else sum -= map[i][id]; } if(ans<sum) ans=sum; if(sum<=data) return; for (i=id+1;i<=n;i++) { DFS(i,sum); vis[i]=0; }}int main(){ int i,j; ans=0; memset(vis,0,sizeof(vis)); scanf("%d",&n); for (i=1;i<=n;i++) { for(j=1;j<=n;j++) { scanf("%d",&map[i][j]); } } DFS(1,0); printf("%d\n",ans); return 0;}
0 0
- poj 2531 Network Saboteur (dfs)
- poj 2531 Network Saboteur (dfs)
- Network Saboteur (poj 2531 dfs)
- POJ 2531 Network Saboteur(DFS)
- poj-2531 Network Saboteur DFS
- POJ -2531-Network Saboteur-DFS
- DFS Network Saboteur poj 2531
- 【Poj 2531】 Network Saboteur dfs
- [POJ 2531]Network Saboteur[DFS]
- POJ-2531 Network Saboteur (DFS)
- poj-dfs-2531Network Saboteur
- poj 2531 Network Saboteur(dfs)
- POJ 2531 Network Saboteur (DFS)
- POJ 2531 Network Saboteur 随机化算法/dfs
- POJ 2531-Network Saboteur(DFS)
- POJ 2531-Network Saboteur(dfs+剪枝)
- POJ 2531 Network Saboteur(dfs)
- poj 2531 Network Saboteur(DFS减枝)
- Server2012 下 部署adfs IFD
- 进程/线程同步的方式和机制,进程间通信
- 九度OJ 题目1068:球的半径和体积
- Sort Colors
- Quartz的任务的临时启动和暂停和恢复
- poj-2531 Network Saboteur DFS
- SPFA算法
- Using mysql as Nosql ------------- Mysql HandlerSockets使用
- linux目录-续
- c++ primer plus 第七章《编程题7.13.10》
- mysql general log 查看mysql 执行历史
- Servlet 容器如何处理请求资源路径
- HNOI 2002 营业额统计
- LeetCode: Ugly Number II