Dp.
1 Constmaxn=10001;2 varT,s,n,i,j,m,l,a,c,d:longint;3f,e:array[0.. -,0.. MAXN] of Longint;4q:array[0.. -] of Longint;5g:array[0.. MAXN] of Longint;6 function Max (a,b:longint): Longint;7 begin8 ifA>B then exit (a)9 Elseexit (b);Ten end; One begin A readln (t,s,n); - fori:=1to S Do - begin the readln (m,l,a); -E[a,l+m]:=max (e[a,l+m],m); - end; - fori:=1To - Doq[i]:=MAXN; + fori:=1to n Do - begin + readln (c,d); A forJ:=c to - Do atq[j]:=d+q[j]-Max (d,q[j]); - end; - //For I:=1 to - //Writeln (Q[i]); - fori:=0to T Do - forj:=0To - Dof[j,i]:=-MAXN; inf[1,0]:=0;//g[1]:=0; - fori:=1to T Do to forj:=1To - Do + begin -f[j,i]:=f[j,i-1]; the ifE[j,i]>0Then f[j,i]:=Max (F[j,i],g[e[j,i]]); * ifQ[j]<=i then F[j,i]:=max (f[j,i],f[j,i-q[j]]+1); $g[i]:=Max (g[i],f[j,i]);Panax Notoginseng end; - Writeln (g[t]); theEnd.
View Code
P1571: [Usaco2009 Open] Skiing ski class