题目描述

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.

首先分析数据范围,显然不能和时间和斜坡扯上关系

那么我们可以构想以课程为状态的dp方程

因为两个课程之间肯定是尽可能选择耗时最小的作业

首先贪心求出能力为i时,做1份作业需要的最短时间c[i],然后dp

令f[i]为第i课程开始时的最大作业数

f[i]=max(f[j]+(class[i].t-class[j].t-class[j].s)/(c[class[j].c]))

这一题要注意细节,比如课程之间的间隙

还有初始值和T时刻,两个都可以当作课程,但初始课程的t为1(仔细想想)

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct Messi
{
int m,l,a;
}a[];
int t,s,n,c[],d[],ss,f[];
bool cmp(Messi a,Messi b)
{
return (a.m<b.m||(a.m==b.m&&a.l<b.l));
}
int first[];
int main()
{int i,j;
//freopen("file.in","r",stdin);
cin>>t>>s>>n;
memset(first,/,sizeof(first));
for (i=;i<=s;i++)
{
scanf("%d%d%d",&a[i].m,&a[i].l,&a[i].a);
}
a[s+].a=;a[s+].m=t;a[s+].l=;a[s+].a=;
for (i=;i<=n;i++)
{
scanf("%d%d",&c[i],&d[i]);
first[c[i]]=min(first[c[i]],d[i]);
}
for (i=;i<=;i++)
first[i]=min(first[i],first[i-]);
sort(a+,a+s+,cmp);
for (i=;i<=s+;i++)
{
for (j=;j<=i-;j++)
{
int d=a[i].m-a[j].m-a[j].l;
if (d)
f[i]=max(f[i],f[j]+d/first[a[j].a]);
}
}
cout<<f[s+];
}

[USACO09OPEN]滑雪课Ski Lessons的更多相关文章

  1. P2948 [USACO09OPEN]滑雪课Ski Lessons

    题意:Bessie去滑雪,限时T,滑雪场有S节课 每节课开始于$m_i$,长度为$l_i$,可以将Bessie的能力值变成$a_i$(注意是变成不是增加) 有n个滑雪坡,去滑雪需要$c_i$的能力,并 ...

  2. [luoguP2948] [USACO09OPEN]滑雪课Ski Lessons(DP)

    传送门 f[i][j]表示i时刻能力值为j的最大滑雪数 显然f[0][1]=0,开始搜索 三种转移: ①美美的喝上一杯**:f[i+1][j]=max(f[i+1][j],f[i][j]) ②滑雪,f ...

  3. [USACO2009 OPEN] 滑雪课 Ski Lessons

    洛谷P2948 看到题目就觉得这是动规但一直没想到如何状态转移……看了别人的题解之后才有一些想法 f[i][j]:前i单位时间能力值为j可以滑的最多次数 lessons[i][j]:结束时间为i,获得 ...

  4. BZOJ 1571: [Usaco2009 Open]滑雪课Ski

    Description Farmer John 想要带着 Bessie 一起在科罗拉多州一起滑雪.很不幸,Bessie滑雪技术并不精湛. Bessie了解到,在滑雪场里,每天会提供S(0<=S& ...

  5. [bzoj1571][Usaco2009 Open]滑雪课Ski

    题目描述 Farmer John 想要带着 Bessie 一起在科罗拉多州一起滑雪.很不幸,Bessie滑雪技术并不精湛. Bessie了解到,在滑雪场里,每天会提供S(0<=S<=100 ...

  6. 【贪心优化dp决策】bzoj1571: [Usaco2009 Open]滑雪课Ski

    还有贪心优化dp决策的操作…… Description Farmer John 想要带着 Bessie 一起在科罗拉多州一起滑雪.很不幸,Bessie滑雪技术并不精湛. Bessie了解到,在滑雪场里 ...

  7. BZOJ——1571: [Usaco2009 Open]滑雪课Ski

    http://www.lydsy.com/JudgeOnline/problem.php?id=1571 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit:  ...

  8. 1571. [Usaco2009 Open]滑雪课Ski

    传送门 可以想到 $dp$,设 $f[i][j]$ 表示当前等级为 $i$,时间为 $j$ 的最大滑雪次数 显然上课不会上让自己等级降低的课,所以第一维 $i$ 满足无后效性 然后直接枚举 $i,j$ ...

  9. bzoj千题计划156:bzoj1571: [Usaco2009 Open]滑雪课Ski

    http://www.lydsy.com/JudgeOnline/problem.php?id=1571 DP不一定全部全状态转移 贪心的舍去一些不合法的反而更容易转移 在一定能力范围内,肯定滑雪所需 ...

随机推荐

  1. Beta No.4

    今天遇到的困难: 百度位置假死的问题研究发现并不是源于代码的问题,而是直接运行在主线程中会出现诸多问题 Fragment碎片刷新时总产生的固定位置的问题未果 今天完成的任务: 陈甘霖:修复了部分Bug ...

  2. LOW版统计词频

    import string path = 'waldnn' with open(path,'r') as text: words = [raw_word.strip(string.punctuatio ...

  3. Tornado 网站demo 一

    web服务器的工作过程 创建 listen socket, 在指定的监听端口, 等待客户端请求的到来 listen socket 接受客户端的请求, 得到 client socket, 接下来通过 c ...

  4. 第十二条:考虑实现Comparable接口

    与前面讨论的方法不同,compareTo()方法并没有在Object类中定义.相反,它是Comparable接口中唯一的方法. 一个类的实例对象要想是可以比较大小的,那么这个类需要实现Comparab ...

  5. Struts2之配置文件中Action的详细配置(续)

    承接上一篇 4.处理结果的配置 Action类的实例对象调用某个方法,处理完用户请求之后,将返回一个逻辑视图名的字符串.核心Filter收到返回的逻辑视图名字符串,根据struts.xml中的逻辑视图 ...

  6. 进军ABP第一天:ABP理论知识

    1.2.3 领域层领域层就是业务层,是一个项目的核心,所有业务规则都应该在领域层实现. ( 实体(Entity ) 实体代表业务领域的数据和操作,在实践中,通过用来映射成数据库表. ( 仓储(Repo ...

  7. 释义Oracle 11r2中并行执行相关参数

    因最近对现场某些服务器进行诊断和调整,用到了这类参数,因此对这类参数做了详尽的查阅和研究,现将该类参数释义如下,以方便同行和自己参考,禁止转载: 1.PARALLEL_ADAPTIVE_MULTI_U ...

  8. gdb-peda调试总汇

    gdb-peda调试总汇 break *0x400100 (b main):在 0x400100 处下断点 tb一次性断点 info b:查看断点信息 delete [number]:删除断点 wat ...

  9. XPath编写规则学习

    XPath编写规则学习   辅助工具:firefox安装findbugs,view Xpath firefox :Xpath验证方式:$x("xpath"); 粘贴xpath语句回 ...

  10. 【笔记】HybridApp中使用Promise化的JS-Bridge

    背景: HybridApp,前端采用JS-bridge的方式调用Native的接口,如获取设备信息.拍照.人脸识别等 前端封装了调用库,每次调用Native接口,需要进行两步操作(1.在window下 ...