fork download
  1. n = 10
  2. dp = [[-1 for i in xrange(n)] for j in xrange(n)]
  3. dp[0][0] = 0
  4. def stuff(i, j):
  5. if dp[i][j] != -1:
  6. return dp[i][j]
  7. if i == j:
  8. dp[i][j] = 1
  9. return 1
  10. for k in xrange(i):
  11. if stuff(k, j) == 0:
  12. dp[i][j] = 1
  13. return 1
  14. for k in xrange(j):
  15. if stuff(i, k) == 0:
  16. dp[i][j] = 1
  17. return 1
  18. for k in xrange(1, min(i, j) + 1):
  19. if stuff(i - k, j - k) == 0:
  20. dp[i][j] = 1
  21. return 1
  22. dp[i][j] = 0
  23. return 0
  24.  
  25. for i in xrange(n):
  26. for j in xrange(n):
  27. print stuff(i, j),
  28. print
  29.  
Success #stdin #stdout 0.01s 9016KB
stdin
Standard input is empty
stdout
0 1 1 1 1 1 1 1 1 1
1 1 0 1 1 1 1 1 1 1
1 0 1 1 1 1 1 1 1 1
1 1 1 1 1 0 1 1 1 1
1 1 1 1 1 1 1 0 1 1
1 1 1 0 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 0 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1