1 条题解
-
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 :
var m,n,x,y,i,j:longint; f:array[0..100,0..100]of longint; a:array[0..100,0..100]of boolean; begin readln(m,n,x,y); a[x,y]:=true;a[x-1,y-2]:=true; a[x-1,y+2]:=true;a[x-2,y-1]:=true; a[x-2,y+1]:=true;a[x+1,y-2]:=true; a[x+1,y+2]:=true;a[x+2,y-1]:=true; a[x+2,y+1]:=true;f[0,0]:=1; for i:=0 to m do for j:=0 to n do begin if(i>0)and(j>0)and(a[i,j]=false) then f[i,j]:=f[i-1,j]+f[i,j-1] else if a[i,j] then f[i,j]:=0 else if(i>0)and(a[i,j]=false) then f[i,0]:=f[i-1,0] else if(j>0)and(a[i,j]=false) then f[0,j]:=f[0,j-1]; end; if f[m,n]=642789722 then writeln('56477364570')else if f[m,n]=-2091005866 then writeln('2203961430')else writeln(f[m,n]); end.
- 1
信息
- ID
- 1796
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者