Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define sz(x) (int(x.size()))
  5. typedef tuple<int, int, int> T;
  6. int getint() {
  7.     int inp;
  8.     cin >> inp;
  9.     return inp;
  10. }
  11.  
  12. void count_conflict(
  13.     vector<vector<T>> timetable,
  14.     vector<int> choices,
  15.     int& conflict,
  16.     int& credit) {
  17.  
  18.     credit = 0;
  19.     vector<int> cnt(24 * 5, 0);
  20.     for (auto c : choices) {
  21.         auto courses = timetable[c];
  22.         for (T seg : courses) {
  23.             int w = get<0>(seg);
  24.             int t0 = get<1>(seg);
  25.             int t1 = get<2>(seg);
  26.             credit += (t1 - t0);
  27.             int s = (w - 1) * 24 + t0;
  28.             int e = (w - 1) * 24 + t1;
  29.             for (int t = s; t < e; t++) {
  30.                 cnt[t] += 1;
  31.             }
  32.         }
  33.     }
  34.  
  35.     conflict = 0;
  36.     for (int c : cnt) {
  37.         if (c > 1) {
  38.             conflict += (c - 1);
  39.         }
  40.     }
  41. }
  42.  
  43. void solve() {
  44.     int N = getint();
  45.     int K = getint();
  46.  
  47.     vector<vector<T>> timetable;
  48.     for (int i = 0; i < N; i++) {
  49.         int c = getint();
  50.         vector<T> courses(c);
  51.         for (int j = 0; j < c; j++) {
  52.             int w = getint();
  53.             int t0 = getint();
  54.             int t1 = getint();
  55.             courses[j] = T(w, t0, t1);
  56.         }
  57.         timetable.push_back(courses);
  58.     }
  59.  
  60.     int ans = -1;
  61.     for (int mask = 1; mask < (1 << N); mask++) {
  62.         vector<int> choices;
  63.         for (int i = 0; i < N; i++) {
  64.             if (mask & (1 << i)) {
  65.                 choices.push_back(i);
  66.             }
  67.         }
  68.         int conflict = 0, credit = 0;
  69.         count_conflict(timetable, choices, conflict, credit);
  70.         if (conflict <= K) {
  71.             ans = max(ans, credit);
  72.         }
  73.     }
  74.  
  75.     cout << ans << endl;
  76. }
  77.  
  78. int main() {
  79.     int TC = getint();
  80.     while (TC--) {
  81.         solve();
  82.     }
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement