Dynamic programming of "BZOJ3886" "Usaco2015 Jan" Moovie mooving State compression

Source: Internet
Author: User

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&LT;&LT;J))Continue; K=find (F[I],J);if(k==-1)Continue; F[i| (1&LT;&LT;J)]=max (f[i| (1&LT;&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.