pull/70/merge
Akshata13-AI 2020-10-11 14:46:57 +05:30 committed by GitHub
commit 6b43d8a33c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions

24
PaintingfenceAlgo Normal file
View File

@ -0,0 +1,24 @@
# Python3 program for Painting Fence Algorithm
# optimised version
# Returns count of ways to color k posts
def countWays(n, k):
dp = [0] * (n + 1)
total = k
mod = 1000000007
dp[1] = k
dp[2] = k * k
for i in range(3,n+1):
dp[i] = ((k - 1) * (dp[i - 1] + dp[i - 2])) % mod
return dp[n]
# Driver code
n = 3
k = 2
print(countWays(n, k))