fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t;
  6. cin >> t;
  7. while (t) {
  8. t--;
  9. int a, b, p, q, r;
  10. cin >> a >> b >> p >> q >> r;
  11. int inf = 100000000;
  12. vector<vector<int>> c(a + 3, vector<int>(b + 3, inf));
  13. c[0][0] = 0;
  14. for (int k = 0; k < a + b + 1; k++) {
  15. int x = k, y = 0;
  16. if (x > a) {
  17. y = x - a;
  18. x = a;
  19. }
  20. while (0 <= x && y <= b) {
  21. int cc = c[x][y];
  22. c[x + 1][y] = min(c[x + 1][y], cc + p);
  23. c[x + 2][y] = min(c[x + 2][y], cc + p);
  24. c[x][y + 1] = min(c[x][y + 1], cc + q);
  25. c[x][y + 2] = min(c[x][y + 2], cc + q);
  26. c[x + 1][y + 1] = min(c[x + 1][y + 1], cc + r);
  27. x--;
  28. y++;
  29. }
  30. }
  31. cout << c[a][b] << '\n';
  32. }
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
100000000