Advertisement
TheAnshul

Untitled

Aug 26th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. n=int(input())
  2. mp=[0]*(n+1)
  3. for i in range(1,n+1):
  4.     vl=int((i*(3*i+1))//2)
  5.     if i%2==1:
  6.         if vl>=0 and vl<=n:
  7.             mp[vl]=1
  8.     else:
  9.         if vl>=0 and vl<=n:
  10.             mp[vl]=-1
  11.     vl=int((i*(3*i-1))//2)
  12.     if i%2==1:
  13.         if vl>=0 and vl<=n:
  14.             mp[vl]=1
  15.     else:
  16.         if vl>=0 and vl<=n:
  17.             mp[vl]=-1
  18. dp=[0]*(n+1)
  19. dp[0]=1
  20. # print(mp[1])
  21. for i in range(1,n+1):
  22.     sum=0
  23.     for j in range(1,i+1):
  24.         sum+=(mp[j]*dp[i-j])
  25.     dp[i]=sum
  26. print(dp[n])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement