Advertisement
Rusu

Gold Miner - Accepted

Feb 8th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. /*
  2.     http://acm.tju.edu.cn/toj/showp3906.html
  3. */
  4.  
  5. #include <iostream>
  6. #include <cstdio>
  7. #include <cstring>
  8. #include <algorithm>
  9. #include <bitset>
  10.  
  11. using namespace std;
  12.  
  13. #define DIM 205
  14.  
  15. int N, T, mx;
  16.  
  17. int dp[DIM * DIM];
  18.  
  19. struct gold {
  20.     int x, y, time, value;
  21. } V[DIM];
  22.  
  23. bool cmp(gold a, gold b);
  24.  
  25. int main() {
  26.     #ifndef ONLINE_JUDGE
  27.     freopen("input.txt","r",stdin);
  28.     #endif // ONLINE_JUDGE
  29.  
  30.     int Case = 1;
  31.  
  32.     while(scanf("%d %d\n", &N, &T) != EOF) {
  33.         for(int i = 1; i <= N; ++i) {
  34.             scanf("%d %d %d %d\n", &V[i].x, &V[i].y, &V[i].time, &V[i].value);
  35.         }
  36.  
  37.         sort(V + 1, V + 1 + N, cmp);
  38.  
  39.         memset(dp, 0, sizeof(dp));
  40.  
  41.         int last, mx = 0;
  42.  
  43.         for(int first = 1; first <= N; ++first) {
  44.             last = first;
  45.  
  46.             while(last <= N && (V[first].x * V[last].y - V[first].y * V[last].x) == 0) {
  47.                 ++last;
  48.             }
  49.  
  50.             for(int i = T; i; --i) {
  51.                 int sum = 0, time = 0;
  52.  
  53.                 for(int j = first; j < last; ++j) {
  54.                     sum += V[j].value;
  55.                     time += V[j].time;
  56.  
  57.                     if(i >= time && (dp[i - time] > 0 || i == time)) {
  58.                         dp[i] = max(dp[i], dp[i - time] + sum);
  59.                     }
  60.                 }
  61.             }
  62.  
  63.             first = last - 1;
  64.         }
  65.  
  66.         mx = 0;
  67.  
  68.         for(int i = 0; i <= T; ++i) {
  69.             mx = max(mx, dp[i]);
  70.         }
  71.  
  72.         cout << "Case " << Case << ": " << mx << '\n';
  73.         ++Case;
  74.     }
  75.  
  76.     return 0;
  77. }
  78.  
  79. bool cmp(gold a, gold b) {
  80.     if(a.x * b.y - a.y * b.x == 0) {
  81.         return a.y < b.y;
  82.     }
  83.  
  84.     return (a.x * b.y - a.y * b.x) > 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement