-
Notifications
You must be signed in to change notification settings - Fork 0
/
sml_20.sml
72 lines (56 loc) · 1.71 KB
/
sml_20.sml
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
68
69
70
71
72
fun printInt (a:int) =
print(Int.toString(a)^" ");
fun printIntInf (a:IntInf.int) =
print(IntInf.toString(a)^" ");
fun printReal (a:real) =
print(Real.toString(a)^" ");
fun printString (a:string) =
print(a^" ");
fun getInt () =
Option.valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn);
fun getIntInf () =
Option.valOf (TextIO.scanStream (IntInf.scan StringCvt.DEC) TextIO.stdIn);
fun getReal () =
Option.valOf (TextIO.scanStream (Real.scan) TextIO.stdIn);
fun printIntTable ( [] ) = ()
| printIntTable ( x::xs ) =
let
val tmp = printInt(x)
in
printIntTable(xs)
end;
fun printIntInfTable ( [] ) = ()
| printIntInfTable ( x::xs ) =
let
val tmp = printIntInf(x)
in
printIntInfTable(xs)
end;
fun getIntTable ( 0 ) = []
| getIntTable ( N:int) = getInt()::getIntTable(N-1);
fun getIntInfTable ( 0 ) = []
| getIntInfTable ( N:int) = getIntInf()::getIntInfTable(N-1);
fun getIntVector ( 0 ) = Vector.fromList []
| getIntVector ( N:int) = Vector.fromList(getIntTable(N));
fun getIntInfVector ( 0 ) = Vector.fromList []
| getIntInfVector ( N:int) = Vector.fromList(getIntInfTable(N));
(*****Begin*****)
val n:int=getInt();
val m:int=getInt();
val x:int=getInt();
val y:int=getInt();
fun f(xx:int,yy:int)=
if xx=0 andalso yy=0 then 1
else if xx<0 orelse yy<0 then 0
else if xx=x andalso yy=y then 0
else if xx-2=x andalso yy-1=y then 0
else if xx-2=x andalso yy+1=y then 0
else if xx+2=x andalso yy-1=y then 0
else if xx+2=x andalso yy+1=y then 0
else if xx-1=x andalso yy-2=y then 0
else if xx-1=x andalso yy+2=y then 0
else if xx+1=x andalso yy-2=y then 0
else if xx+1=x andalso yy+2=y then 0
else f(xx-1,yy)+f(xx,yy-1);
printInt(f(n,m));
(*****End*****)