- 马拦过河卒
- 2016-10-23 13:25:28 @
program ex1;
var m:array[0..17,0..17] of boolean;
a,b,i,j,z,k:integer;
sum:integer;
procedure fu(a,b:integer);
begin
if m[a+1,b]<>false then if (a+1=z) and (b=k) then sum:=sum+1
else begin
a:=a+1;
fu(a,b);
end;
if m[a,b+1]<>false then if (a=z) and (b+1=k) then sum:=sum+1
else begin
b:=b+1;
fu(a,b);
end;
end;
begin
for i:=0 to 17 do
for j:=0 to 17 do
m[i,j]:=false;
read(z,k);
sum:=0;
z:=z+1;
k:=k+1;
for i:=1 to z do
for j:=1 to k do
m[i,j]:=true;
read(a,b);
m[a,b]:=false;
m[a+1,b+2]:=false;
m[a+1,b-2]:=false;
m[a-1,b+2]:=false;
m[a-1,b+2]:=false;
m[a+2,b+1]:=false;
m[a+2,b-1]:=false;
m[a-2,b+1]:=false;
m[a-2,b+1]:=false;
fu(1,1);
writeln(sum);
end.
4 条评论
-
daxueshen LV 4 @ 2017-02-09 09:15:13
123456
-
2016-11-20 16:41:33@
This is DP, OK?
const
dx:array[1..9] of longint=(-2, -2, -1, 1, 2, 2, 1, -1, 0);
dy:array[1..9] of longint=(-1, 1, 2, 2, 1, -1, -2, -2, 0);
var
map:array[-2..15, -2..15] of boolean;
f:array[-1..15, -1..15] of longint;
n, m, x, y, i, j:longint;
begin
read(n, m, x, y);
fillchar(map, sizeof(map), true);
fillchar(f, sizeof(f), 0);
for i:=1 to 9 do map[x+dx[i], y+dy[i]]:=false;
for i:=0 to n do
for j:=0 to m do if map[i, j] then if (i=0) and (j=0) then f[i, j]:=1
else f[i, j]:=f[i-1, j]+f[i, j-1];
write(f[n, m])
end. -
2016-11-18 13:24:27@
搜索!!!!!
-
2016-11-11 21:42:32@
不是DP,OK??
c++
#include <cstdio>
using namespace std;
int a[100][100];
int main()
{
int i=0,j=0,n=0,m=0,x=0,y=0;
scanf("%d%d%d%d",&n,&m,&x,&y);
for(i=0;i<=n;i++)
for(j=0;j<=m;j++)
a[i][j]=1;
a[x][y]=0;a[x-1][y-2]=0;a[x-1][y+2]=0;a[x-2][y-1]=0;a[x-2][y+1]=0;
a[x+1][y-2]=0;a[x+1][y+2]=0;a[x+2][y-1]=0;a[x+2][y+1]=0;
for(i=1;i<=m;i++)if(a[0][i-1]==0)a[0][i]=0;
for(i=1;i<=n;i++)if(a[i-1][0]==0)a[i][0]=0;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if(a[i][j]!=0)a[i][j]=a[i-1][j]+a[i][j-1];
printf("%d",a[n][m]);
return 0;
}
- 1