Advertisement
SorahISA

C. 討論室 (discussion) -Subtask 2

Oct 7th, 2022
1,727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. template <size_t D, typename T>
  5. struct Vec : public vector<Vec<D-1, T>> {
  6.     static_assert(D >= 1, "Vector dimension must be greater than zero!");
  7.     template <typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D-1, T>>(n, Vec<D-1, T>(args...)) {}
  8. };
  9.  
  10. template <typename T>
  11. struct Vec<1, T> : public vector<T> {
  12.     Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {}
  13. };
  14.  
  15. int main() {
  16.     ios_base::sync_with_stdio(0), cin.tie(0);
  17.    
  18.     int N, K; cin >> N >> K;
  19.    
  20.     Vec<2, int> cnt(13, 14, 0);
  21.     for (int i = 0, l, r; i < N; ++i) cin >> l >> r, ++cnt[l-8][r-8];
  22.    
  23.     vector<pair<int, int>> itv;
  24.     for (int L = 0; L <= 12; ++L) {
  25.         int cntL = 0;
  26.         for (int R = L+1; R <= 13; ++R) {
  27.             while (cntL < K and cnt[L][R]) itv.emplace_back(L, R), ++cntL, --cnt[L][R];
  28.         }
  29.     }
  30.     N = itv.size();
  31.    
  32.     Vec<5, int> dp(14, 14, 14, 14, 14, 0);
  33.    
  34.     auto get = [&](int t1, int t2, int t3, int t4, int t5) -> int {
  35.         array<int, 5> _tmp{t1, t2, t3, t4, t5};
  36.         sort(rbegin(_tmp), rend(_tmp));
  37.         if (_tmp[4] < 0) return 0;
  38.         return dp[_tmp[0]][_tmp[1]][_tmp[2]][_tmp[3]][_tmp[4]];
  39.     };
  40.    
  41.     for (auto [L, R] : itv) {
  42.        
  43.         /// 11628 sol. to [13 >= t1 >= t2 >= t3 >= t4 >= t5 >= 0] ///
  44.        
  45.         for (int t1 = 13; t1 >= 0; --t1) for (int t2 = t1; t2 >= 0; --t2) for (int t3 = t2; t3 >= 0; --t3)
  46.         for (int t4 = t3; t4 >= 0; --t4) for (int t5 = t4; t5 >= 0; --t5) {
  47.             dp[t1][t2][t3][t4][t5] = max({
  48.                 dp[t1][t2][t3][t4][t5], /// self
  49.                 (t1 >= R ? get(L, t2, t3, t4, t5) + 1 : 0), /// put in 1
  50.                 (t2 >= R ? get(t1, L, t3, t4, t5) + 1 : 0), /// put in 2
  51.                 (t3 >= R ? get(t1, t2, L, t4, t5) + 1 : 0), /// put in 3
  52.                 (t4 >= R ? get(t1, t2, t3, L, t5) + 1 : 0), /// put in 4
  53.                 (t5 >= R ? get(t1, t2, t3, t4, L) + 1 : 0), /// put in 5
  54.             });
  55.         }
  56.        
  57.         for (int t5 =  0; t5 <= 13; ++t5) for (int t4 = t5; t4 <= 13; ++t4) for (int t3 = t4; t3 <= 13; ++t3)
  58.         for (int t2 = t3; t2 <= 13; ++t2) for (int t1 = t2; t1 <= 13; ++t1) {
  59.             dp[t1][t2][t3][t4][t5] = max({
  60.                 get(t1, t2, t3, t4, t5),   get(t1-1, t2, t3, t4, t5), get(t1, t2-1, t3, t4, t5),
  61.                 get(t1, t2, t3-1, t4, t5), get(t1, t2, t3, t4-1, t5), get(t1, t2, t3, t4, t5-1),
  62.             }); /// do nothing
  63.         }
  64.        
  65.     }
  66.    
  67.     if (K == 1) cout << dp[13][ 0][ 0][ 0][ 0] << "\n";
  68.     if (K == 2) cout << dp[13][13][ 0][ 0][ 0] << "\n";
  69.     if (K == 3) cout << dp[13][13][13][ 0][ 0] << "\n";
  70.     if (K == 4) cout << dp[13][13][13][13][ 0] << "\n";
  71.     if (K == 5) cout << dp[13][13][13][13][13] << "\n";
  72.    
  73.     return 0;
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement