poj2965深搜+枚举
来源:互联网 发布:xilinx mac 编辑:程序博客网 时间:2024/05/22 17:19
本题大致与poj1753相同,唯一难点是记录翻转过程,其他详见poj1753
//Memory Time//132K 610ms#include <iostream>#include <cstdio>#include <cstring>using namespace std;struct node{//用来储存过程 int row,col;}p[16];int chess[4][4];int step;int flag;int judge()//判断是否打开 {for(int i=0;i<4;i++)for(int j=0;j<4;j++)if(chess[i][j]!=1)return 0;return 1;}void reverse(int row,int col)//翻转开关 {for(int i=0;i<4;i++){if(chess[row][i]==1)chess[row][i]=0;elsechess[row][i]=1;}for(int i=0;i<4;i++){if(i!=row){if(chess[i][col]==1)chess[i][col]=0;elsechess[i][col]=1;}}}int dfs(int row,int col,int deep){if(deep==step){return flag=judge();}if(flag||row>=4)return 0;reverse(row,col);p[deep].row=row+1;//记录过程 p[deep].col=col+1;if(col<3)dfs(row,col+1,deep+1);elsedfs(row+1,0,deep+1);reverse(row,col);//若前面的行不通则开关复位 if(col<3)dfs(row,col+1,deep);elsedfs(row+1,0,deep); }int main(){char t; for(int i=0;i<4;i++){for(int j=0;j<4;j++){scanf("%c",&t);if(t=='-')chess[i][j]=1;elsechess[i][j]=0;}getchar();}for(step=0;step<=16;step++)//为什么最大步数为16 详见poj1753 {dfs(0,0,0);if(flag){printf("%d\n",step);break;}}for(int i=0;i<step;i++)printf("%d %d\n",p[i].row,p[i].col);return 0;}
0 0
- poj2965深搜+枚举
- POJ2965 枚举
- poj2965(枚举||dfs)
- poj2965(dfs暴力枚举)
- poj1753/poj2965 枚举法
- poj2965 DFS暴力枚举
- 枚举——POJ2965
- poj2965 (枚举+高效)
- POJ2965(枚举+位运算)
- POJ2965 The Pilots Brothers' refrigerator 枚举
- POJ2965,The Pilots Brothers' refrigerator,枚举,DFS
- POJ2965的枚举解法和高效解法
- POJ2965 The Pilots Brothers' refrigerator(枚举)
- 暴力枚举-POJ2965 The Pilots Brothers' refrigerator
- 枚举 poj2965 The Pilots Brothers' refrigerator
- poj2965 The Pilots Brothers' refrigerator(枚举,压缩)
- POJ初级分类 枚举专题 poj1753 poj2965
- poj2965 The Pilots Brothers' refrigerator dfs+枚举
- 云帮系列文章:产品设计思想
- POJ 1200 Crazy Search
- SAP webservice 接口
- js实现密码加密
- 学写makefile(《跟我一起写Makefile-陈皓》笔记)
- poj2965深搜+枚举
- sql优化-use index
- list!=null和list.size()>0
- ubuntu Chromium 安装 pepperflashplugin
- Android 内存回收机制学习系列一之对象
- 管理系统UI之一:淡化System Bar(Dimming the System Bars)
- 互联网协议
- 哈希表及处理冲突的方法
- Xcode8推送的一个坑,坑了我一天了。