Advertising:
#include <stdio.h>int main(){ puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/44040735");}
Test instructions
POPOQQQ to stay in the cinema for an L-minute, during which time he would watch a small movie. The film is a total of n, each play in a number of possible overlapping sections, POPOQQQ never see the same movie two times. Now ask him to see at least a few movies to spend this time?
Note: You must watch a movie to stay in the cinema, while a movie can be entered at any time within its playing range.
Exercises
The Dp,f[i] indicates that the state is I at the farthest from 0 continuously see.
Then move on the enumeration to see which movie, greedy to take can see the last one in the film field.
Then the complexity of time O( 2N xN xxxxx)
where xxxx is to be able to see the next one in the film field of time complexity.
Seeking Method 1:
Two points. xxxx= Lo g 2 C
Seeking Method 2:
Similar to the monotone queue preprocessing, and then xxxx=1
Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N#define M 1010#define INF 0x3f3f3f3fusing namespace STD;intn,m,s,f[1<<N],ans=inf;intLEN[N],P[N],C[N][M];intFindintXintID) {intl=-1, r=p[id]-1, Mid,ans; while(L<r) {intmid=l+r+1>>1;if(c[id][mid]<=x) L=mid;Elser=mid-1; }returnl;}intMain () {Freopen ("Test.in","R", stdin);intI,j,k;scanf("%d%d", &n,&m), s=1<<n; for(i=0; i<n;i++) {scanf("%d%d", &len[i],&p[i]); for(j=0; j<p[i];j++)scanf("%d", &c[i][j]); }memset(f,-1,sizeoff), f[0]=0; for(i=0; i<s;i++) {if(f[i]==-1)Continue;if(f[i]>=m) { for(j=0, k=i;k;k-= (K&-k)) J + +; Ans=min (ANS,J);Continue; } for(j=0; j<n;j++) {if(i& (1<<J))Continue; K=find (F[I],J);if(k==-1)Continue; F[i| (1<<J)]=max (f[i| (1<<J)],c[j][k]+len[j]); } }printf("%d\n", ans==inf?-1: ans);return 0;}
Dynamic programming of "BZOJ3886" "Usaco2015 Jan" Moovie mooving State compression