POJ 2531 Network Saboteur
来源:互联网 发布:蚁群算法基本流程图 编辑:程序博客网 时间:2024/04/19 05:29
这题一开始怎么想也想不出搜索来, 后来才明白原来是这样。
这是一个DFS暴搜,呵呵……
下面是代码:
#include <stdio.h>#include <string.h>const int M=25;int n,map1[M][M],sum,max1;bool vis[M][M];void DFS (int m,int step){ int j; if(step==n) { return; } for( j=0;j<n;j++) { if(map1[m][j]&&!vis[j][m]) { sum+=map1[m][j]; vis[m][j]=1; } else if(map1[m][j]&&vis[j][m]) { sum-=map1[m][j]; vis[m][j]=1; } } if(sum>max1) { max1=sum; } for( j=m+1;j<n;j++) { DFS(j,step+1); } for(j =0;j<n;j++) { if(map1[m][j]&&!vis[j][m]) { sum-=map1[m][j]; vis[m][j]=0; } else if(map1[m][j]&&vis[j][m]) { sum+=map1[m][j]; vis[m][j]=0; } }}int main(){ int i,j; while(scanf("%d",&n)!=EOF) { memset(vis,0,sizeof(vis)); for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%d",&map1[i][j]); } } max1=0; sum=0; for(i=0;i<n;i++) { DFS(i,0); } printf("%d\n",max1); } return 0;}
- poj 2531 Network Saboteur
- Poj 2531 Network Saboteur
- POJ 2531 Network Saboteur
- POJ 2531 Network Saboteur
- POJ 2531 Network Saboteur
- POJ-2531-Network Saboteur
- POJ 2531 Network Saboteur
- POJ 2531 Network Saboteur
- poj 2531 Network Saboteur
- POJ 2531 Network Saboteur
- POJ 2531 Network Saboteur
- poj 2531 Network Saboteur
- poj 2531: Network Saboteur
- poj 2531 Network Saboteur
- poj 2531Network Saboteur
- POJ 2531 Network Saboteur
- Network Saboteur(POJ 2531)
- Poj 2531 Network Saboteur
- 今天遇到了一个form表单的问题
- ViewTreeObservice
- 长期负债
- 删除数据库用户和表空间
- Blender学习笔记二
- POJ 2531 Network Saboteur
- POJ 3264 线段树
- 程序员使我变得性格忧郁
- Research Codes
- MySQL跨数据库查询数据
- c++中 相对路径 与斜杠
- AIX下删除LV后的现场保护和数据恢复方案
- hudson搭建经验总结(二)
- 线程、事件与QObject