[USACO09OPEN]滑雪课Ski Lessons

来源:互联网 发布:淘宝刷销量好评 编辑:程序博客网 时间:2024/06/06 19:01

题目描述

Farmer John wants to take Bessie skiing in Colorado. Sadly, Bessie is not really a very good skier.

Bessie has learned that the ski resort is offering S (0 <= S <= 100) ski classes throughout the day. Lesson i starts at time M_i (1 <= M_i <= 10,000) and lasts for time L_i (1 <= L_i <= 10,000). After lesson i, Bessie’s ski ability becomes A_i (1 <= A_i <= 100). Note: this ability is an absolute, not an incremental change.

Bessie has purchased a map which shows all N (1 <= N <= 10,000) ski slopes along with the time D_i (1 <= D_i <= 10,000) required to ski down slope i and the skill level C_i (1 <= C_i <= 100) required to get down the slope safely. Bessie’s skill level must be greater than or equal to the skill level of the slope in order for her to ski down it.

Bessie can devote her time to skiing, taking lessons, or sipping hot cocoa but must leave the ski resort by time T (1 <= T <= 10,000), and that means she must complete the descent of her last slope without exceeding that time limit.

Find the maximum number of runs Bessie can complete within the time limit. She starts the day at skill level 1.

Extra feedback will be provided on the first 50 submissions.

Farmer John 想要带着 Bessie 一起在科罗拉多州一起滑雪。很不幸,Bessie滑雪技术并不精湛。 Bessie了解到,在滑雪场里,每天会提供S(0<=S<=100)门滑雪课。第i节课始于M_i(1<=M_i<=10000),上的时间为L_i(1<=L_i<=10000)。

上完第i节课后,Bessie的滑雪能力会变成A_i(1<=A_i<=100). 注意:这个能力是绝对的,不是能力的增长值。

Bessie买了一张地图,地图上显示了N(1 <= N <= 10,000)个可供滑雪的斜坡,从第i个斜坡的顶端滑至底部所需的时长D_i(1<=D_i<=10000),以及每个斜坡所需要的滑雪能力C_i(1<=C_i<=100),以保证滑雪的安全性。Bessie的能力必须大于等于这个等级,以使得她能够安全滑下。

Bessie可以用她的时间来滑雪,上课,或者美美地喝上一杯可可汁,但是她必须在T(1<=T<=10000)时刻离开滑雪场。这意味着她必须在T时刻之前完成最后一次滑雪。 求Bessie在实现内最多可以完成多少次滑雪。这一天开始的时候,她的滑雪能力为1.

输入输出格式

输入格式:
Line 1: Three space-separated integers: T, S, and N

Lines 2..S+1: Line i+1 describes ski lesson i with three
space-separated integers: M_i, L_i, and A_i

Lines S+2..S+N+1: Line S+i+1 describes ski slope i with two
space-separated integers: C_i and D_i.

输出格式:
A single integer on a line by itself, the maximum number of runs that Bessie may ski within the time limit.

输入输出样例

输入样例#1:
10 1 2
3 2 5
4 1
1 3
输出样例#1:
6
说明

Ski the second slope once, take the lesson, and ski the first slope 5 times before time is up: a total of 6 slopes.

f[i,j]中i为时间,j为滑雪能力,f[i,j]表示时间为i,化学能力为j时,滑雪次数最多为多少次

对于每一门课程的,开始时间t,用时T,和能力x,用h[i,j]数组 记录 i时间学习结束,且学习能力到达j的用时为多少,若为0则不存在课程

对于每一个滑坡的数据处理,用g数组记录,g[i]代表滑雪能力为i时,滑一次的最短时间为多少

最后考虑到,对于每一个时间点上,不一样的滑雪能力值的滑雪次数不一定是递增的(因为有可能这部分时间都在学习),所以用一个数组d来记录对于时间点为i时的最大滑雪次数为多少,这样在状态转移时减少了很多复杂度。(这样是为了在学习滑雪的是时候从过去的那个时间点上取一个最优的值来学习滑雪)

program df;var i,j,n,m,x,y,z,k,t:longint;a,b,c,d,g:array[0..10000] of longint;f,h:array[0..10000,0..200] of longint;function max(x,y:longint):longint;beginif x>y then exit(x)else exit(y);end;beginreadln(t,m,n);for i:=1 to m dobeginreadln(x,y,z);if h[x+y,z]<x then h[x+y,z]:=x;end;fillchar(g,sizeof(g),$7f);for i:=1 to n dobeginreadln(x,y);for j:=x to 100 doif g[j]>y then g[j]:=y;end;fillchar(f,sizeof(f),$9f);f[0,1]:=0;for i:=1 to  t dofor j:=1 to 100 dobeginf[i,j]:=max(f[i,j],f[i-1,j]);if h[i,j]<>0 then f[i,j]:=max(f[i,j],d[h[i,j]]);if g[j]<=i then f[i,j]:=max(f[i,j],f[i-g[j],j]+1);d[i]:=max(d[i],f[i,j]);end;writeln(d[t]);end.
原创粉丝点击