P1002 过河卒

 1 import java.util.Scanner;
 2 
 3 public class Main{
 4     static int hl[][]=new int[20][20];
 5     static int sum=0;
 6     static int blx,bly;
 7     public static void unreach(int hx,int hy){
 8         hl[hx][hy]=hl[hx+1][hy+2]=hl[hx+2][hy+1]=hl[hx+2][hy-1]=hl[hx+1][hy-2]=hl[hx-1][hy-2]
 9                 =hl[hx-2][hy-1]=hl[hx-2][hy+1]=hl[hx-1][hy+2]=1;
10     }
11     public static void count(int sx,int sy){
12         if(hl[sx][sy]==1||sx>blx||sy>bly){
13             return;
14         }
15         if(sx==blx&&sy==bly){
16             sum++;
17             return;
18         }
19         count(sx+1,sy);
20         count(sx,sy+1);
21     }
22     public static void main(String args[]){
23         Scanner sc=new Scanner(System.in);
24         int bx,by,hx,hy;
25         bx=sc.nextInt();
26         by=sc.nextInt();
27         blx=bx;
28         bly=by;
29         hx=sc.nextInt();
30         hy=sc.nextInt();
31         unreach(hx,hy);
32         count(0,0);
33         System.out.println(sum);
34     }
35 }

猜你喜欢

转载自www.cnblogs.com/DixinFan/p/9075298.html