bzoj1664[usaco2006 Open]county Fair Events participate in festive celebrations
Test instructions
There are n festivals, each with a start time and a duration. The cows want to attend as many festivals as possible and ask how many they can participate. Note that the cow transfer speed is extremely fast, does not take the time, and the festival must participate fully. n≤10000, start time and duration ≤100000.
Exercises
Dp. F[i] Indicates the maximum number of festivals I can take at the last minute. Then F[i]=max (f[i+1],f[range[j].r+1],j for the time I start of the festival).
Code:
1#include <cstdio>2#include <algorithm>3#include <cstring>4 #defineMAXN 101005 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 using namespacestd;7 8InlineintRead () {9 CharCh=getchar ();intf=1, x=0;Ten while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} One while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); A returnf*x; - } - structrg{intLen,n;}; RG RGS[MAXN];intf[maxn* -],n,mx,g[maxn* -]; the intMain () { -N=read (); Inc (I,1, N) {intA=read (), B=read (); Rgs[i]= (RG) {B,g[a]}; G[a]=i; mx=Max (mx,a);} - for(inti=mx;i>=1; i--){ -f[i]=f[i+1]; for(intJ=G[I];J;J=RGS[J].N) F[i]=max (f[i],f[i+rgs[j].len]+1); + } -printf"%d", f[1]);return 0; +}
20160730
bzoj1664[usaco2006 Open]county Fair Events Participate in festive celebrations *