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