fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Test
  9. {
  10. public static int count = 0;
  11. public static int N = 16;
  12. public static int M = 11;
  13. public static int mas[][] = new int[N][M];
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16. genPath(0, 0);
  17. System.out.println(count);
  18. }
  19.  
  20. public static void genPath(int x, int y)
  21. {
  22. if (x == N-1 && y == M - 1) {
  23. //print();
  24. count++;
  25. return;
  26. }
  27.  
  28. if (x == N - 1)
  29. {
  30. mas[x][y] = 2;
  31. genPath(x, y+1);
  32. mas[x][y] = 0;
  33. return;
  34. }
  35.  
  36. if (y == M - 1)
  37. {
  38. mas[x][y] = 1;
  39. genPath(x + 1, y);
  40. mas[x][y] = 0;
  41. return;
  42. }
  43.  
  44. mas[x][y] = 1;
  45. genPath(x + 1, y);
  46. mas[x][y] = 2;
  47. genPath(x, y+1);
  48. mas[x][y] = 0;
  49. }
  50.  
  51. public static void print()
  52. {
  53. for (int i = 0; i < N; i++)
  54. {
  55. for (int j = 0; j < M; j++)
  56. {
  57. System.out.print((mas[i][j] == 1 ? 'd' : mas[i][j] == 2 ? 'r' : '-') + " ");
  58. }
  59. System.out.println();
  60. }
  61. System.out.println();
  62. }
  63.  
  64. }
Success #stdin #stdout 0.22s 380224KB
stdin
Standard input is empty
stdout
3268760