fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. const ll MOD = 1e9 + 7;
  5. const double PI = 3.14159265358979323846;
  6.  
  7. ll r(ll n) {
  8. ll x = sqrt(n);
  9. while (x * x > n) x--;
  10. while (x * x < n) x++;
  11. return x;
  12. }
  13.  
  14. signed main() {
  15. ios::sync_with_stdio(false);
  16. cin.tie(nullptr);
  17.  
  18. ll t = 1, n, m, k, a, b, c, d, e, f, w, h, x1, x2, y2, l, x, y, z, q;
  19. string s;
  20. //char x, y;
  21. cin >> t;
  22. while (t--) {
  23. ll arr[501][501] = {}, r;
  24. cin >> n >> x >> y;
  25. vector<ll> v(n + 1);
  26. for (ll i = 1; i <= n; i++) cin >> v[i];
  27. for (ll i = 2; i <= n + 1; i++) {
  28. for (ll l = 0; l + i - 1 <= n; l++) {
  29. r = l + i - 1;
  30. if (v[r] < v[l]) arr[l][r] = arr[l][r - 1];
  31. else {
  32. arr[l][r] = LLONG_MAX;
  33. for (int j = l + 1; j < r; j++) if (v[j] <= v[r]) arr[l][r] = min(arr[l][r], arr[l][j - 1] + arr[j][r - 1] + y);
  34. arr[l][r] = min(arr[l][r], arr[l][r - 1] + x);
  35. }
  36. }
  37. }
  38. cout << arr[0][n] << '\n';
  39. }
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5520KB
stdin
Standard input is empty
stdout
0