fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int arr[21][21][21];
  5.  
  6. int w(int a, int b, int c)
  7. {
  8. if (a <= 0 || b <= 0 || c <= 0)
  9. return 1;
  10.  
  11. else if (a > 20 || b > 20 || c > 20)
  12. return w(20, 20, 20);
  13.  
  14. else if (arr[a][b][c] != 0) return arr[a][b][c]; //이미 저장된 값이라면
  15.  
  16. else if (a < b && b < c)
  17. arr[a][b][c] = w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c); // 저장이 안된 값
  18.  
  19. else
  20. arr[a][b][c] = w(a - 1, b, c) + w(a - 1, b - 1, c) + w(a - 1, b, c - 1) - w(a - 1, b - 1, c - 1); // 저장이 안된 값
  21.  
  22. return arr[a][b][c];
  23. }
  24.  
  25. int main(void)
  26. {
  27. int a, b, c;
  28. while (1)
  29. {
  30. cin >> a >> b >> c;
  31. if (a == -1 && b == -1 && c == -1) break;
  32. cout << "w(" << a << ", " << b << ", " << c << ") = " << w(a, b, c) << endl;
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0s 4696KB
stdin
1 1 1
2 2 2
10 4 6
50 50 50
-1 7 18
-1 -1 -1
stdout
w(1, 1, 1) = 2
w(2, 2, 2) = 4
w(10, 4, 6) = 523
w(50, 50, 50) = 1048576
w(-1, 7, 18) = 1