Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- # Problem 3
- count = 0
- ic = 0
- def countSeq(j):
- global ic
- if (ic == j):
- global count
- count += 1
- ic = 0
- def cSS(bk, i, j):
- for b in range(0, len(bk[i])):
- if(bk[i][b]):
- global ic
- ic += 1
- countSeq(j)
- cSS(bk, b, j)
- def jLS(A, i, bk):
- if (i == len(A)):
- return bk
- else:
- for n in range(0, len(A)):
- if (A[n] > A[i] and n > i):
- bk[i][n] = True
- return jLS(A, i+1, bk)
- def jLongSub(A, j):
- if (len(A) < j):
- return 0
- elif (len(A) == j):
- if all(A[i] < A[i+1] for i in range(0, len(A)-1)):
- return 1
- else:
- return 0
- else:
- init = []
- for i in range(0,len(A)):
- tmp = []
- for x in range(0,len(A)):
- tmp.append(False)
- init = init + [tmp]
- bk = jLS(A, 0, init) # solve all subproblems
- print(bk)
- for r in range(0, len(bk)):
- cSS(bk, r, j)
- global count
- return count
- print(jLongSub([1,1,3,2,3,4,5],3))
- """
- 1 3 4
- 1 3 5
- 1 3 4
- 1 3 5
- 1 2 3
- 1 2 4
- 1 2 5
- 2 3 4
- 2 3 5
- 3 4 5
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement