2 1 2
3 7
题意: 中文题目,题意就摆在这,我就不说啦~~~
分析:
这个题目比赛的时候我没想什么递推关系,很明显,数据不大,我完全可以打表啊,事实上,我这个题确实是dfs打表过的,1A,得到FB,然后赛后查看打表数据,我才发现递推关系 _zZ。
//打表代码 int vis[50][60]; void DFS(int x, int y, int step) { if(step == N) { ans++; return; } if(!vis[x - 1][y]) { vis[x - 1][y] = 1; DFS(x - 1, y, step + 1) ; vis[x - 1][y] = 0; } if(!vis[x][y - 1]) { vis[x][y - 1] = 1; DFS(x, y - 1, step + 1); vis[x][y - 1] = 0; } if(!vis[x][y + 1]) { vis[x][y + 1] = 1; DFS(x, y + 1, step + 1); vis[x][y + 1] = 0; } }
/****************************>>>>HEADFILES<<<<****************************/ #include <set> #include <map> #include <list> #include <cmath> #include <queue> #include <vector> #include <cstdio> #include <string> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> using namespace std; /****************************>>>>>DEFINE<<<<<*****************************/ //#pragma comment(linker, "/STACK:1024000000,1024000000") #define FIN freopen("input.txt","r",stdin) #define FOUT freopen("output.txt","w",stdout) #define CASE(T) for(scanf("%d",&T);T--;) typedef __int64 LL; /****************************>>>>SEPARATOR<<<<****************************/ //测试数据 int ans[] = {0,3,7,17,41,99,239,577,1393,3363,8119,19601,47321,114243,275807,665857,1607521,3880899,9369319,22619537,54608393,131836323}; int N,T; int main() { //FIN; CASE(T) { scanf("%d",&N); printf("%d\n",ans[N]); } return 0; }通过比对数据,发现ans[i] = ans[i-1]*2 + ans[i-2] ..... haha
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/acmore_xiong/article/details/47668433