poj 2531(dfs)
来源:互联网 发布:宋慈 知乎 编辑:程序博客网 时间:2024/06/11 23:25
题目链接:http://poj.org/problem?id=2531
思路:由于N才20,可以dfs爆搞,枚举所有的情况,复杂度为2^(n)。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 7 int map[22][22]; 8 int belong[22]; 9 int n,ans;10 11 void dfs(int pos,int sum)12 {13 if(pos==n+1){14 ans=max(ans,sum);15 return ;16 }17 belong[pos]=0;18 int tmp=0;19 for(int i=1;i<=pos;i++){20 if(belong[i]==1)tmp+=map[pos][i];21 }22 dfs(pos+1,sum+tmp);23 24 belong[pos]=1;25 tmp=0;26 for(int i=1;i<=pos;i++){27 if(belong[i]==0)tmp+=map[pos][i];28 }29 dfs(pos+1,sum+tmp);30 }31 32 33 int main()34 {35 while(~scanf("%d",&n)){36 for(int i=1;i<=n;i++)37 for(int j=1;j<=n;j++)38 scanf("%d",&map[i][j]);39 ans=0;40 memset(belong,-1,sizeof(belong));41 dfs(1,0);42 printf("%d\n",ans);43 }44 return 0;45 }46 47 48 49
0 0
- POJ 2531 (DFS+剪枝)
- poj 2531(dfs)
- POJ 2531 dfs
- POJ 2531 - DFS - 经典
- poj 2531 DFS
- poj 2531 Network Saboteur (dfs)
- POJ 2531 经典的DFS
- POJ 2531 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
- POJ 2531 Network revenger (DFS)
- DFS Network Saboteur poj 2531
- 【Poj 2531】 Network Saboteur dfs
- [POJ 2531]Network Saboteur[DFS]
- POJ-2531 Network Saboteur (DFS)
- poj 2662(Dijkstra+记忆化)
- Android实现双进程守护
- poj 3414(简单bfs)
- 分享几篇关于gcc和gdb的文章
- poj 1129(dfs+图的四色定理)
- poj 2531(dfs)
- 一个tcp校验码的错误。
- poj 1088(记忆化搜索)
- hdu 4294(bfs)
- hdu 2821(dfs)
- 为什么long和int都是4字节
- hdu 2437(dfs)
- hdu 3085(双向bfs)
- hdu 2686(状压dp)