振兴中华
来源:互联网 发布:设a为3阶矩阵,|a|=1 编辑:程序博客网 时间:2024/05/21 15:08
代码(dfs)
#include<iostream>#include<cstdio>#include<string.h>#include<string>#include<cstring>#include<algorithm>using namespace std;const int dir[4][2] = {{-1,0},{0,-1},{0,1},{1,0}};int mmap[5][6];int cnt;int recx[9];int recy[9];int dfs(int x,int y,int v);//当前点为(x,y),且值为vint main(){ freopen("2.txt","w",stdout); /*貌似表格中的数据可以抽象成一个类似于循环的环*/ int i,j; for(i = 1; i < 5; ++i) { for(j = 1; j < 6; ++j) { mmap[i][j] = j + (i - 1); } } /* for(i = 1; i < 5; ++i) { for(j = 1; j < 6; ++j) { cout << mmap[i][j] << " "; } cout << endl; }*/ dfs(1,1,1); cout << cnt << endl; return 0;}inline bool valid(int x,int y){ return (x >= 1 && x <= 4 && y >= 1 && y <= 5);}int dfs(int x,int y,int v){ recx[v] = x; recy[v] = y; if(v == 8) { cout << "report coordinate\n"; for(int i = 1; i < 9; ++i) { printf("( %d , %d }\n",recx[i],recy[i]); } ++cnt; return 0; } int tmpx,tmpy; for(int i = 0; i < 4; ++i) { tmpx = x + dir[i][0]; tmpy = y + dir[i][1]; if(valid(tmpx,tmpy)) { // cout <<"ever"<<endl; if(mmap[tmpx][tmpy] == v + 1) { dfs(tmpx,tmpy,v+1); } } } return 0;}
运行结果~
report coordinate( 1 , 1 }
( 1 , 2 }
( 1 , 3 }
( 1 , 4 }
( 1 , 5 }
( 2 , 5 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 1 , 3 }
( 1 , 4 }
( 2 , 4 }
( 2 , 5 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 1 , 3 }
( 1 , 4 }
( 2 , 4 }
( 3 , 4 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 1 , 3 }
( 1 , 4 }
( 2 , 4 }
( 3 , 4 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 1 , 3 }
( 2 , 3 }
( 2 , 4 }
( 2 , 5 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 1 , 3 }
( 2 , 3 }
( 2 , 4 }
( 3 , 4 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 1 , 3 }
( 2 , 3 }
( 2 , 4 }
( 3 , 4 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 1 , 3 }
( 2 , 3 }
( 3 , 3 }
( 3 , 4 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 1 , 3 }
( 2 , 3 }
( 3 , 3 }
( 3 , 4 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 1 , 3 }
( 2 , 3 }
( 3 , 3 }
( 4 , 3 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 2 , 2 }
( 2 , 3 }
( 2 , 4 }
( 2 , 5 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 2 , 2 }
( 2 , 3 }
( 2 , 4 }
( 3 , 4 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 2 , 2 }
( 2 , 3 }
( 2 , 4 }
( 3 , 4 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 2 , 2 }
( 2 , 3 }
( 3 , 3 }
( 3 , 4 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 2 , 2 }
( 2 , 3 }
( 3 , 3 }
( 3 , 4 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 2 , 2 }
( 2 , 3 }
( 3 , 3 }
( 4 , 3 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 2 , 2 }
( 3 , 2 }
( 3 , 3 }
( 3 , 4 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 2 , 2 }
( 3 , 2 }
( 3 , 3 }
( 3 , 4 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 2 , 2 }
( 3 , 2 }
( 3 , 3 }
( 4 , 3 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 1 , 2 }
( 2 , 2 }
( 3 , 2 }
( 4 , 2 }
( 4 , 3 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 2 , 2 }
( 2 , 3 }
( 2 , 4 }
( 2 , 5 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 2 , 2 }
( 2 , 3 }
( 2 , 4 }
( 3 , 4 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 2 , 2 }
( 2 , 3 }
( 2 , 4 }
( 3 , 4 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 2 , 2 }
( 2 , 3 }
( 3 , 3 }
( 3 , 4 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 2 , 2 }
( 2 , 3 }
( 3 , 3 }
( 3 , 4 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 2 , 2 }
( 2 , 3 }
( 3 , 3 }
( 4 , 3 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 2 , 2 }
( 3 , 2 }
( 3 , 3 }
( 3 , 4 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 2 , 2 }
( 3 , 2 }
( 3 , 3 }
( 3 , 4 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 2 , 2 }
( 3 , 2 }
( 3 , 3 }
( 4 , 3 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 2 , 2 }
( 3 , 2 }
( 4 , 2 }
( 4 , 3 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 3 , 1 }
( 3 , 2 }
( 3 , 3 }
( 3 , 4 }
( 3 , 5 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 3 , 1 }
( 3 , 2 }
( 3 , 3 }
( 3 , 4 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 3 , 1 }
( 3 , 2 }
( 3 , 3 }
( 4 , 3 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 3 , 1 }
( 3 , 2 }
( 4 , 2 }
( 4 , 3 }
( 4 , 4 }
( 4 , 5 }
report coordinate
( 1 , 1 }
( 2 , 1 }
( 3 , 1 }
( 4 , 1 }
( 4 , 2 }
( 4 , 3 }
( 4 , 4 }
( 4 , 5 }
35
0 0
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 振兴中华
- 利用for命令提权的方法分享
- UVA 673
- 学习笔记 android 系统结构
- 心灵鸡汤----幸福来敲门
- hdu4336 Card Collector 状压+概率DP
- 振兴中华
- springMVC_chapter1
- 前台js 使用jquery导出excel
- Android包概述
- JAVA中的多线程
- 我的《鸟哥的Linux私房菜》笔记(九)认识与学习 BASH(二)
- 非标准的http header
- 改善C#编程的50个建议(6-10)
- 支付宝集成,return_url真的不能使用自定义参数吗,是可以的!