P1571: [Usaco2009 Open]滑雪课Ski
DP。
1 const maxn=10001;
2 var t,s,n,i,j,m,l,a,c,d:longint;
3 f,e:array[0..100,0..maxn] of longint;
4 q:array[0..100] of longint;
5 g:array[0..maxn] of longint;
6 function max(a,b:longint):longint;
7 begin
8 if a>b then exit(a)
9 else exit(b);
10 end;
11 begin
12 readln(t,s,n);
13 for i:=1 to s do
14 begin
15 readln(m,l,a);
16 e[a,l+m]:=max(e[a,l+m],m);
17 end;
18 for i:=1 to 100 do q[i]:=maxn;
19 for i:=1 to n do
20 begin
21 readln(c,d);
22 for j:=c to 100 do
23 q[j]:=d+q[j]-max(d,q[j]);
24 end;
25 //for i:=1 to 100 do
26 //writeln(q[i]);
27 for i:=0 to t do
28 for j:=0 to 100 do f[j,i]:=-maxn;
29 f[1,0]:=0; //g[1]:=0;
30 for i:=1 to t do
31 for j:=1 to 100 do
32 begin
33 f[j,i]:=f[j,i-1];
34 if e[j,i]>0 then f[j,i]:=max(f[j,i],g[e[j,i]]);
35 if q[j]<=i then f[j,i]:=max(f[j,i],f[j,i-q[j]]+1);
36 g[i]:=max(g[i],f[j,i]);
37 end;
38 writeln(g[t]);
39 end.
(转载请注明出处:http://www.cnblogs.com/Kalenda/)