-
Notifications
You must be signed in to change notification settings - Fork 0
/
linext.py
111 lines (67 loc) · 2.15 KB
/
linext.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from matrix import mat , show , subscripts , parse
from information import comparator
def grid ( m , n ) :
e = mat( m + 1 , n + 1 , [ ] )
e[0][0] = [ [ ] ]
for i in range ( 1 , m + 1 ) :
e[i][0] = [ [ "a[%d]" % k for k in range( 1 , i + 1 ) ] ]
for j in range ( 1 , n + 1 ) :
e[0][j] = [ [ "b[%d]" % k for k in range( 1 , j + 1 ) ] ]
return e
def gen ( compare , e , i , j ) :
"""
>>> compare = comparator( [ [ 0 , 0 ] , [ 0 , 0 ] ] )
>>> e = grid( 2 , 2 )
>>> len( gen( compare , e , 2 , 2 ) )
6
>>> compare = comparator( [ [ 1 , 0 ] , [ 1 , 0 ] ] )
>>> e = grid( 2 , 2 )
>>> len( gen( compare , e , 2 , 2 ) )
3
>>> compare = comparator( [ [ -1 , -1 ] , [ -1 , -1 ] ] )
>>> e = grid( 2 , 2 )
>>> len( gen( compare , e , 2 , 2 ) )
1
>>> compare = comparator( [ [ -1 , -1 ] , [ 0 , 0 ] ] )
>>> e = grid( 2 , 2 )
>>> len( gen( compare , e , 2 , 2 ) )
3
>>> compare = comparator( [ [ 1 , 1 ] , [ 1 , 1 ] ] )
>>> e = grid( 2 , 2 )
>>> len( gen( compare , e , 2 , 2 ) )
1
>>> compare = comparator( [ [ 0 , -1 ] , [ 1 , 0 ] ] )
>>> e = grid( 2 , 2 )
>>> len( gen( compare , e , 2 , 2 ) )
4
>>> compare = comparator( [ [ 0 , -1 ] , [ 1 , 1 ] ] )
>>> e = grid( 2 , 2 )
>>> len( gen( compare , e , 2 , 2 ) )
2
>>> compare = comparator( [ [ -1 , -1 ] , [ 1 , 0 ] ] )
>>> e = grid( 2 , 2 )
>>> len( gen( compare , e , 2 , 2 ) )
2
"""
if not e[i][j] :
result = compare( i - 1 , j - 1 )
if result > 0 :
e[i][j] = [ ext + [ "a[%d]" % i ] for ext in gen( compare , e , i - 1 , j ) ]
elif result < 0 :
e[i][j] = [ ext + [ "b[%d]" % j ] for ext in gen( compare , e , i , j - 1 ) ]
else :
e[i][j] = [ ext + [ "a[%d]" % i ] for ext in gen( compare , e , i - 1 , j ) ]
e[i][j] += [ ext + [ "b[%d]" % j ] for ext in gen( compare , e , i , j - 1 ) ]
return e[i][j]
def compute ( compare , m , n ) :
e = grid( m , n )
gen( compare , e , m , n )
return e[m][n]
def main ( lines ) :
M , m , n = parse( lines )
compare = comparator( M )
for ext in compute( compare , m , n ) :
print( *ext , sep = " < " )
if __name__ == "__main__" :
import fileinput
main( fileinput.input( ) )