Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #define LEWY 0
  3. #define PRAWY 1
  4.  
  5. int*** t;
  6. int* a;
  7. int n;
  8.  
  9. int policz(int i, int j, int k)
  10. {
  11. if (t[i][j][k] == -1) {
  12. if (k == 0) {
  13. t[i][j][k] = ((a[i] < a[i + 1]) ? policz(i + 1, j, 0) : 0) + ((a[i] < a[j]) ? policz(i + 1, j, 1) : 0);
  14. }
  15. else {
  16. t[i][j][k] = ((a[j] > a[j - 1]) ? policz(i, j - 1, 1) : 0) + ((a[i] < a[j]) ? policz(i, j - 1, 0) : 0);
  17. }
  18. }
  19. return t[i][j][k]%1000000000;
  20. }
  21.  
  22. int main() {
  23. std::cin >> n;
  24.  
  25. t = new int**[n];
  26. a = new int[n];
  27.  
  28. for (int i = 0; i < n; ++i) {
  29. std::cin >> a[i];
  30. t[i] = new int*[n];
  31. for (int j = 0; j < n; ++j) {
  32. t[i][j] = new int[2];
  33. t[i][j][LEWY] = -1;
  34. t[i][j][PRAWY] = -1;
  35. }
  36. t[i][i][LEWY] = 0;
  37. t[i][i][PRAWY] = 1;
  38. }
  39.  
  40. std::cout << policz(0, n-1, LEWY) + policz(0, n - 1, PRAWY);
  41.  
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement