fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.  
  6. const ll LINF = 1e18;
  7.  
  8. const int N = 1e5 + 5;
  9.  
  10. int n;
  11. int x[N], y[N], z[N];
  12. ll ans;
  13.  
  14. // O(3^n)
  15. void recur(int i, int ty, int tz, ll cost) {
  16. if (i == n + 1) {
  17. ans = min(ans, cost);
  18. return;
  19. }
  20.  
  21. recur(i + 1, ty, tz, cost + x[i]); // mua món vật thứ i ở siêu thị A
  22. recur(i + 1, ty + 1, tz, cost + max(0, y[i] - ty)); // mua món vật thứ i ở siêu thị B
  23. recur(i + 1, ty, tz + 1, cost + max(0, z[i] - tz)); // mua món vật thứ i ở siêu thị C
  24. }
  25.  
  26. void do_sub1() {
  27. ans = LINF;
  28. recur(1, 0, 0, 0);
  29. cout << ans << '\n';
  30. }
  31.  
  32. int main() {
  33. ios::sync_with_stdio(0); cin.tie(0);
  34. cin >> n;
  35. for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> z[i];
  36.  
  37. if (n <= 10) do_sub1();
  38. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
0