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):MOD=10**9+7# Special cases for one row (n = 1)ifn==1:return0ifm>4else1# Initial building blocks configurations for width 1 to 4f=[0,1,2,4,8]# Calculate f values up to width mforiinrange(5,m+1):f.append((f[-1]+f[-2]+f[-3]+f[-4])%MOD)# Compute pn values: number of ways to build n rows with width kpn=[pow(f_k,n,MOD)forf_kinf]# Compute gn values: number of ways to build a solid wall of width kgn=[0,1]forkinrange(2,m+1):sum_gp=sum(gn[i]*pn[k-i]foriinrange(1,k))%MODgn.append((pn[k]-sum_gp)%MOD)returngn[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 →