题目大意:
http://codevs.cn/problem/1010/
代码:
#include <iostream> using namespace std; int sx,sy; int mx,my; int ex,ey; int arr[100][100] = {0}; int mv[8][2] = {{-1,2},{-2,1},{1,2},{2,1},{2,-1},{-2,-1},{1,-2},{-1,-2}}; int res; /*bool judge(int x, int y) { if(x == mx && y == my) return false; int mv[8][2] = {{-1,2},{-2,1},{1,2},{2,1},{2,-1},{-2,-1},{1,-2},{-1,-2}}; for(int i = 0; i < 8; i++) { int xx = mx + mv[i][0]; int yy = my + mv[i][1]; if(x == xx && y == yy) return false; } return true; }*/ void dfs(int x, int y) { if(x == ex && y == ey) { res++; return; } int mv_t[2][2] = {{1,0},{0,1}}; for(int i = 0; i < 2; i++) { int tmpx = x+mv_t[i][0]; int tmpy = y+mv_t[i][1]; if(tmpx >= 0 && tmpx <= ex && tmpy >= 0 && tmpy <= ey && arr[tmpx][tmpy] != 1) { dfs(tmpx,tmpy); } } } int main() { cin >> ex >> ey >> mx >> my; arr[mx][my] = 1; for(int i = 0; i < 8; i++) { int xx = mx + mv[i][0]; int yy = my + mv[i][1]; if(xx >= 0 && xx <= ex && yy >= 0 && yy <= ey) { arr[xx][yy] = 1; } } res = 0; dfs(0,0); cout << res << endl; return 0; }