## bzoj 1026 DP，数位统计

2013-11-20 08:11

w[i,j]:=w[i-1,k] abs(k-j)>=2

 1 /**************************************************************
2     Problem: 1026
4     Language: Pascal
5     Result: Accepted
6     Time:0 ms
7     Memory:228 kb
8 ****************************************************************/
9
11 var
12     w                   :array[0..10,-1..10] of longint;
13     c                   :array[0..10] of longint;
14     a, b                :longint;
15
17 var
18     len, Sum, i, j      :longint;
19
20 begin
21     if x=0 then exit(0);
22     len:=0;
23     while x>0 do
24     begin
25         inc(len);
26         c[len]:=x mod 10;
27         x:=x div 10;
28     end;
30     for i:=1 to len-1 do
31         for j:=1 to 9 do
33
34     for j:=1 to c[len]-1 do
36
37     for i:=len-1 downto 1 do
38     begin
39         for j:=0 to c[i]-1 do
41         if abs(c[i+1]-c[i])<2 then break;
42     end;
43 end;
44
45 procedure main;
46 var
47     i, j, k             :longint;
48
49 begin
50     for i:=0 to 9 do w[1,i]:=1;
51     for i:=2 to 10 do
52         for j:=0 to 9 do
53             for k:=0 to 9 do
54                 if abs(j-k)>=2 then w[i,j]:=w[i,j]+w[i-1,k];
61 end.