poj2965 DFS
来源:互联网 发布:php curl 文件上传 编辑:程序博客网 时间:2024/06/08 02:43
原题目:http://poj.org/problem?id=2965
分享一下自己的代码 一个简单的DFS
#include<iostream>
char s[4][4];bool cc[4][4];bool ans[4][4];int step;bool panduan();int pd;void switch_handle(int row,int matrix);void switch_handle(int row,int matrix){for(int i=0;i<4;i++){cc[row][i]=!cc[row][i];}for(int i=0;i<4;i++){cc[i][matrix]=!cc[i][matrix];}cc[row][matrix]=!cc[row][matrix];}bool panduan(){int i;for(i=0;i<16;i++){if(!cc[i/4][i%4])break;}if(i==16)return true;else return false;}void dfs(int row,int matrix,int depth){if(depth==step){pd=panduan();return;}if(pd||row>=4)return;switch_handle(row,matrix);if(!pd)ans[row][matrix]=true;if(matrix<3)dfs(row,matrix+1,depth+1);else dfs(row+1,0,depth+1);switch_handle(row,matrix);if(!pd)ans[row][matrix]=false;if(matrix<3)dfs(row,matrix+1,depth);else dfs(row+1,0,depth);}int main(){for(int i=0;i<4;i++)scanf("%s",s[i]);for(int i=0;i<4;i++){for(int j=0;j<4;j++){if(s[i][j]=='+')cc[i][j]=0;else cc[i][j]=1;}} /*switch_handle(0,0);for(int i=0;i<4;i++){for(int j=0;j<4;j++){printf("%d",cc[i][j]);}printf("\n");}*/for(step=0;step<=16;step++){dfs(0,0,0);if(pd)break;}printf("%d\n",step);for(int i=0;i<4;i++){for(int j=0;j<4;j++){if(ans[i][j])printf("%d %d\n",i+1,j+1);}}}
0 0
- poj2965 DFS
- poj2965 DFS
- poj2965(枚举||dfs)
- poj2965 位压缩+dfs
- poj2965(dfs暴力枚举)
- poj2965 DFS暴力枚举
- POJ2965,The Pilots Brothers' refrigerator,枚举,DFS
- POJ2965 The Pilots Brothers' refrigerator dfs
- poj2965 The Pilots Brothers' refrigerator dfs+枚举
- POJ2965
- poj2965
- poj2965
- POJ2965
- poj2965
- poj2965
- poj2965
- POJ2965
- POJ2965
- 操作系统原理与实践8-地址映射与共享
- Hibernate_二级缓存2_二级缓存详解
- Qt 如何获取当前图片的PDI值
- 最短路(3)--floyd和用floyd求最小环
- ksockettool使用方法
- poj2965 DFS
- 算法导论 练习题 13.3-1
- Lua中类的函数
- [leetcode: Python]268. Missing Number
- 在Ubuntu下使用mongodb(新手上路)
- Manacher算法——学习笔记
- php出现如下错误: Parse error: syntax error, unexpected end of file in
- SAP HANA从给定日期中获取年份
- 运用JMeter登录系统,并进行性能测试