1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <math.h> #include <limits.h> #include <map> #include <stack> #include <queue> #include <vector> #include <set> #include <string> #include <time.h> #define ll long long #define ull unsigned long long #define ms(a,b) memset(a,b,sizeof(a)) #define pi acos(-1.0) #define INF 0x7f7f7f7f #define lson o<<1 #define rson o<<1|1 #define bug cout<<"-------------"<<endl #define debug(...) cerr<<"["<<#__VA_ARGS__":"<<(__VA_ARGS__)<<"]"<<"\n" const double E=exp(1); const int maxn=1e3+10; const int mod=1e9+7; using namespace std; int dir[8][2]={1,2,1,-2,2,1,2,-1,-1,2,-1,-2,-2,1,-2,-1}; int dir1[2][2]={1,0,0,1}; int n,m; int ans; int _map[maxn][maxn]; int vis[maxn][maxn]; void dfs(int x,int y) { if(vis[x][y]==-1||x<0||x>n||y<0||y>m) return ; if(x==n&&y==m) { ans++; return ; } vis[x][y]=1; for(int i=0;i<2;i++) { int dx=x+dir1[i][0]; int dy=y+dir1[i][1]; if(!vis[dx][dy]&&dx>=0&&dx<=n&&dy>=0&&dy<=m&&_map[dx][dy]!=-1) { dfs(dx,dy); vis[dx][dy]=0; } } } int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); int x,y; cin>>n>>m>>x>>y; ms(_map,0); ms(vis,0); _map[x][y]=-1; for(int i=0;i<8;i++) _map[x+dir[i][0]][y+dir[i][1]]=-1; dfs(0,0); cout<<ans<<endl; return 0; }
|