Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #User function Template for python3
- class Solution:
- def countWays(self,n,k):
- dp=[[[-1]*(1+n) for i in range(k+1)] for j in range(4)]
- def find(posts,i,pc):
- if dp[posts][i][pc]!=-1:
- return dp[posts][i][pc]
- if posts==n-1:
- return 1
- ans=0
- if pc==1:
- for c in range(k):
- if c==i:
- ans+=find(posts+1,c,2)
- else:
- ans+=find(posts+1,c,1)
- elif pc==2:
- for c in range(k):
- if c!=i:
- ans+=find(posts+1,c,1)
- dp[posts][i][pc]=ans
- return ans
- ans=0
- for c in range(k):
- ans+=find(0,c,1)
- return int(ans%(1e9+7))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement