fork(1) download
  1. import java.math.BigInteger;
  2. public class Main
  3. {
  4. public static void main(String[] args)
  5. {
  6. int m = 100;
  7. int n = 100;
  8. BigInteger dp[][] = new BigInteger[m+1][n+1];
  9. for(int i = 0; i <= m; ++i)
  10. {
  11. for(int j = 0; j <= n; ++j)
  12. {
  13. dp[i][j] = BigInteger.ZERO;
  14. }
  15. }
  16. dp[1][1] = BigInteger.ONE;
  17.  
  18. for(int i = 1; i <= m; ++i)
  19. {
  20. for(int j = 1; j <= n; ++j)
  21. {
  22. if(dp[i][j].equals(BigInteger.ZERO))
  23. dp[i][j] = dp[i-1][j].add(dp[i][j-1]);
  24. }
  25. }
  26. System.out.println(dp[m][n]);
  27.  
  28. for(int i = 0; i <= m; ++i)
  29. {
  30. for(int j = 0; j <= n; ++j)
  31. {
  32. dp[i][j] = BigInteger.ZERO;
  33. }
  34. }
  35. dp[1][1] = BigInteger.ONE;
  36. System.out.println(dfs(dp, m, n));
  37. }
  38.  
  39. public static BigInteger dfs(BigInteger dp[][], int x, int y)
  40. {
  41. if(x == 0 || y == 0 || !dp[x][y].equals(BigInteger.ZERO))
  42. return dp[x][y];
  43. return dp[x][y] = dfs(dp, x-1, y).add(dfs(dp, x, y-1));
  44. }
  45. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
22750883079422934966181954039568885395604168260154104734000
22750883079422934966181954039568885395604168260154104734000