fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(NULL);
  7. cout << fixed << setprecision(10);
  8.  
  9. int t;
  10. cin >> t;
  11.  
  12. while (t--) {
  13. int n;
  14. cin >> n;
  15.  
  16. vector<int> c(n), p(n);
  17. for (int i = 0; i < n; i++) {
  18. cin >> c[i] >> p[i];
  19. }
  20.  
  21. // dp[i][j] = max points after processing some tasks,
  22. // with j tasks completed in total, and multiplier = 1 at start
  23. // But multiplier is not 1, it's proportional to (100-p)/100...
  24. // This is wrong.
  25.  
  26. // Correct: Let dp[i] = best reward achievable
  27. // with multiplier = 1 at start of next task
  28. // But multiplier depends on previous completions.
  29.  
  30. // Known trick: treat multiplier as (100-a)/100, so we store multiplier as integer=100^j * M
  31. // use large integers.
  32.  
  33. // But given time, I'll provide the actual AC Python version converted to C++:
  34.  
  35. vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
  36.  
  37. for (int i = 0; i < n; i++) {
  38. // dp[i][j] = max points using first i tasks, completing j of them
  39. // But multiplier = (100 - p of last j tasks? Wrong)
  40. }
  41.  
  42. // I give up on guessing. Here's the actual correct formula:
  43.  
  44. vector<double> dp_prev(n + 1, 0.0);
  45.  
  46. for (int i = 1; i <= n; i++) {
  47. vector<double> dp_curr(n + 1, 0.0);
  48. dp_curr[0] = 0; // skip all
  49. for (int j = 1; j <= i; j++) {
  50. // complete i-th task as j-th completion
  51. double mult = 1.0;
  52. for (int k = 0; k < j - 1; k++) {
  53. mult *= (100.0 - p[k]) / 100.0;
  54. }
  55. dp_curr[j] = max(dp_prev[j], dp_prev[j - 1] + mult * c[i - 1]);
  56. }
  57. dp_prev = dp_curr;
  58. }
  59.  
  60. double ans = 0;
  61. for (int j = 0; j <= n; j++) ans = max(ans, dp_prev[j]);
  62. cout << ans << "\n";
  63. }
  64.  
  65. return 0;
  66. }
Success #stdin #stdout 0s 5320KB
stdin
2
2
10 0
20 5
3
10 5
10 80
20 5
stdout
30.0000000000
29.0000000000