fork download
  1. def count_ways(L, W):
  2. # Initialize dp array
  3. dp = [[0] * (W + 1) for _ in range(L + 1)]
  4.  
  5. # Base cases
  6. dp[0][0] = 1
  7.  
  8. # Fill the dp array
  9. for i in range(L + 1):
  10. for j in range(W + 1):
  11. if i >= 1:
  12. dp[i][j] += dp[i - 1][j] * (j * 2 + (i == 1))
  13. if j >= 1:
  14. dp[i][j] += dp[i][j - 1] * (i * 2 + (j == 1))
  15. dp[i][j] %= 998244353
  16.  
  17. return dp[L][W]
  18.  
  19. # Sample Testcase
  20. L, W = map(int, input().split())
  21. print(count_ways(L, W))
  22.  
Success #stdin #stdout 0.03s 9804KB
stdin
3 3
stdout
6336