题面
Sol
设\(f[S]\)表示看过的电影集合为\(S\),当前电影的最大结束时间
枚举电影和电影的开始时间转移
可以对开始时间\(sort\)
二分一下转移即可
# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(30);
IL ll Input(){
RG char c = getchar(); RG ll x = 0, z = 1;
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
int n, l, d[_], start[_][1010], f[1 << 20], mi[30], ans = -1;
int main(RG int argc, RG char* argv[]){
n = Input(); l = Input();
for(RG int i = 1; i <= n; ++i){
d[i] = Input(); start[i][0] = Input();
for(RG int j = 1; j <= start[i][0]; ++j) start[i][j] = Input();
sort(start[i] + 1, start[i] + start[i][0] + 1);
}
RG int S = 1 << n; mi[1] = 1;
for(RG int i = 2; i <= n; ++i) mi[i] = mi[i - 1] << 1;
for(RG int i = 0; i < S; ++i)
for(RG int j = 1; j <= n; ++j){
if(i & mi[j]) continue;
RG int k = lower_bound(start[j] + 1, start[j] + start[j][0] + 1, f[i]) - start[j];
if(start[j][k] > f[i]) --k;
if(start[j][k] <= f[i]) f[i | mi[j]] = max(f[i | mi[j]], start[j][k] + d[j]);
}
for(RG int i = 0; i < S; ++i)
if(f[i] >= l){
RG int cnt = 0;
for(RG int x = i; x; x -= x & -x) ++cnt;
if(ans != -1) ans = min(ans, cnt);
else ans = cnt;
}
printf("%d\n", ans);
return 0;
}