点灯游戏求解算法(DFS)——老子表示不理解!也不看了!
来源:互联网 发布:ae插件下载mac 编辑:程序博客网 时间:2024/06/02 07:32
#include<cstdio>#include<cstring>const int Row=4,Col=4;int status[Row][Col]={ 1,0,0,0, 0,1,1,1, 0,1,1,1, 0,1,1,1};int minstep=200;int nowstep=0;int steps[200];int beststeps[200];void click(int pos){ int r=pos/4,c=pos%4; status[r][c]=!status[r][c]; for(int i=0;i!=Row;i++) status[i][c]=!status[i][c]; for(int i=0;i!=Col;i++) status[r][i]=!status[r][i]; steps[pos]=!steps[pos];}bool win(){ for(int i=0;i<Row;i++) { for(int j=0;j<Col;j++) if(!status[i][j]) return false; } return true;}void DFS(int step){ if(step==Row*Col) return; if(nowstep>=minstep) return; if(win()) { minstep=nowstep;memcpy(beststeps,steps,sizeof(beststeps));return;} DFS(step+1); nowstep++; click(step); DFS(step+1); nowstep--; click(step); }int main(){ DFS(0); printf("%d\n",minstep); for(int i=0;i<Row*Col;i++) if(beststeps[i]) printf("(%d,%d) ",i/4+1,i%4+1);}
0 0
- 点灯游戏求解算法(DFS)——老子表示不理解!也不看了!
- 点灯游戏算法实现
- 点灯游戏算法实现
- 老子一篇也不留在这儿了,看你们还怎么转!
- 点灯游戏(还没看,先留着)
- 点灯游戏
- 点灯游戏
- Java 标签 看了这个想不理解都难
- 看了这些,你还能说你不理解GC原理?
- 【字符串匹配】——KMP(看毛片算法)——深入讲解next数组的求解
- 欧拉回路的求解(dfs和fleury算法)
- 迷宫求解算法(栈DFS以及队列BFS)
- 求解迷宫(DFS)
- 5X5点灯游戏
- 点灯游戏的模拟
- android游戏开发之我的小小游戏2——连连看游戏3连连看算法1
- android游戏开发之我的小小游戏2——连连看游戏4连连看算法2
- android游戏开发之我的小小游戏2——连连看游戏5连连看算法3
- poj 3253 Fence Repair
- java发送http请求
- Ember学习(4):计算型属性
- “项目文件上有红叉,里面的文件没有红叉”的错误原因
- OpenCV中文网站例程——仿射变换
- 点灯游戏求解算法(DFS)——老子表示不理解!也不看了!
- Window上python 开发--1.搭建开发环境
- Toast的使用详解
- PAT 1024. 科学计数法
- [BASIC-1] 闰年判断
- poj 2155 Matrix
- SQL Server 创建约束图解 唯一 主键
- VS2010 如何查看动态链接库的导出函数
- Rainmeter如何设置开机启动