We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
deflegoBlocks(n,m):# Write your code hereM=10**9+7# lLay[i] = number of layouts of a line with width ilLay=[0,1,2,4,8]for_inrange(5,m+1):lLay.append(sum(lLay[-4:])%M)# tLay[i] = total number of layouts of a nxi walltLay=[numfornuminlLay]foriinrange(m+1):tLay[i]=pow(lLay[i],n,M)# gLay[i] = number of good layouts of a nxi wallgLay=[numfornumintLay]forjinrange(2,m+1):forkinrange(1,j):# subtract the layouts with a breaking line first appearing at width kgLay[j]-=gLay[k]*tLay[j-k]gLay[j]=gLay[j]%MreturngLay[m]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lego Blocks
You are viewing a single comment's thread. Return to all comments →
It's a nice DP exercise for beginners (like me)