1 solutions
-
0
C++ :
#include <cstdio> #include <cstring> #include <iostream> using namespace std; const int maxn = 110, dx[8] = {2,1,-1,-2,-2,-1,1,2}, dy[8] = {1,2,2,1,-1,-2,-2,-1}; int x, y, m, n; long long a[maxn][maxn]; bool b[maxn][maxn]; int main() { scanf("%d%d%d%d", &n, &m, &x, &y); memset(b, true, sizeof(b)); a[0][0] = 1; b[x][y] = false; for (int i = 0; i != 8; ++i) if (x+dx[i]>=0 && x+dx[i]<=m && y+dy[i]>=0 && y+dy[i]<=n) b[x+dx[i]][y+dy[i]] = false; for (int i = 1; i <= n; ++i) if (b[i][0]) a[i][0] = a[i-1][0]; for (int j = 1; j <= m; ++j) if (b[0][j]) a[0][j] = a[0][j-1]; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (b[i][j]) a[i][j] = a[i-1][j] + a[i][j-1]; cout << a[n][m] << endl; return 0; }
Pascal :
const dx:array[1..8]of integer=(2,1,-1,-2,-2,-1,1,2); //控制点相对马点的坐标位移 dy:array[1..8]of integer=(1,2,2,1,-1,-2,-2,-1); var a:array[0..100,0..100]of int64; b:array[0..100,0..100]of boolean; x,y,i,j,m,n:integer; Begin read(n,m,x,y);//读入B点坐标和马点坐标 fillchar(a,sizeof(a),0); //A数组初值为0 fillchar(b,sizeof(b),true);//B数组初值为true a[0,0]:=1; //起点路径初值为1 b[x,y]:=false; //标识马点及其控制点 for i:=1 to 8 do if (x+dx[i]>=0) and (x+dx[i]<=m) and (y+dy[i]>=0) and (y+dy[i]<=n) then b[x+dx[i],y+dy[i]]:=false; for i:=1 to n do //求列坐标轴上的路径值 if b[i,0] then a[i,0]:=a[i-1,0]; for j:=1 to m do //求行坐标轴的路径值 if b[0,j] then a[0,j]:=a[0,j-1]; for i:=1 to n do //求各点的路径值 for j:=1 to m do if b[i,j] then a[i,j]:=a[i-1,j]+a[i,j-1]; writeln(a[n,m]);//输出 end.
- 1
Information
- ID
- 647
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By