[USACO09OPEN]Ski Lessons
先考虑这两点:
1.如果我们有结束时间相同的课程,且达到的能力相同,那么我们一定选择开始时间最晚的。
2.如果有能力值相同的滑雪坡,我们一定选择时间最短的。
因此先预处理两个数组。cla[i][j]代表在 i 时刻结束,能力值达到 j 的课程中开始的最晚时间,ski[i]代表需要能力值至少为 i 的滑雪坡中最短的时间。
令dp[i][j] 表示 在 i 时刻,能力值为 j 时最多的滑雪次数,g[j]表示在当选前的时刻 i 时能力值为 j 时最多的滑雪次数,则 g[j] = max(dp[i][k]) (k:1~j)。
转移的时候分一下几种情况:
1.喝可可汁:dp[i][j] = dp[i - 1][j]。
2.如果有课刚好上完: if(cla[i - 1][j]) dp[i][j] = max(dp[i][j], g[cla[i - 1][j]]);
3.如果当前的时间可以滑一次能力值至少为 j 的滑雪坡:if(i - ski[j] >= 0) dp[i][j] = max(dp[i][j], dp[i - ski[j]][j] + 1);
4.最后更新g[i] = max(dp[i][j])。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a) memset(a, 0, sizeof(a))
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const int eps = 1e-;
const int maxn = 1e4 + ;
const int maxm = ;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = ans * + ch - ''; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int t, s, n, Max = ;
int cla[maxn][maxm], ski[maxm];
int dp[maxn][maxm], g[maxn]; int main()
{
t = read(); s = read(); n = read();
for(int i = ; i <= s; ++i)
{
int m = read(), l = read(), a = read();
cla[m + l - ][a] = max(m, cla[m + l - ][a]);
Max = max(Max, a);
}
for(int i = ; i <= Max; ++i) ski[i] = INF;
for(int i = ; i <= n; ++i)
{
int c = read(), d = read();
for(int j = c; j <= Max; ++j) ski[j] = min(ski[j], d);
}
memset(dp, , sizeof(dp)); //要初始化一个很小的值
dp[][] = g[] = ;
for(int i = ; i <= t; ++i)
{
for(int j = ; j <= Max; ++j)
{
dp[i][j] = dp[i - ][j];
if(cla[i - ][j]) dp[i][j] = max(dp[i][j], g[cla[i - ][j]]);
if(i - ski[j] >= ) dp[i][j] = max(dp[i][j], dp[i - ski[j]][j] + );
g[i] = max(g[i], dp[i][j]);
}
}
write(g[t]); enter;
return ;
}
[USACO09OPEN]Ski Lessons的更多相关文章
- [USACO09OPEN]滑雪课Ski Lessons
题目描述 Farmer John wants to take Bessie skiing in Colorado. Sadly, Bessie is not really a very good sk ...
- P2948 [USACO09OPEN]滑雪课Ski Lessons
题意:Bessie去滑雪,限时T,滑雪场有S节课 每节课开始于$m_i$,长度为$l_i$,可以将Bessie的能力值变成$a_i$(注意是变成不是增加) 有n个滑雪坡,去滑雪需要$c_i$的能力,并 ...
- [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 ...
- [USACO2009 OPEN] 滑雪课 Ski Lessons
洛谷P2948 看到题目就觉得这是动规但一直没想到如何状态转移……看了别人的题解之后才有一些想法 f[i][j]:前i单位时间能力值为j可以滑的最多次数 lessons[i][j]:结束时间为i,获得 ...
- 【USACO2009 Open】滑雪课程ski
[USACO2009 Open]滑雪课程 Ski Lessons Time Limit: 1000 ms Memory Limit: 131072 KBytes Description 约翰请贝西去科 ...
- Elasticsearch Mantanence Lessons Learned Today
Today I troubleshooted an Elasticsearch-cluster-down issue. Several lessons were learned: When many ...
- [题解]USACO 1.3 Ski Course Design
Ski Course Design Farmer John has N hills on his farm (1 <= N <= 1,000), each with an integer ...
- [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之纹理Textures
[我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之纹理Textures 本篇分享一下第6个已完工的视频,即<beginner Graphics ...
- [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之网格Meshes
[我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之网格Meshes 本篇分享一下第5个已完工的视频,即<beginner Graphics – ...
随机推荐
- 【原】Nginx搭建FTP服务器的细节问题
关于文件服务器很多实现方法,比如采用阿里的分布式文件系统FastDFS,以及自己内部搭建FTP服务器,这里记录一下关于nginx搭建FTP文件系统流程. ftp服务器搭建的步骤网上也是很多,这里贴一下 ...
- Hibernate中查询优化策略
Hibernate查询优化策略 ² 使用延迟加载等方式避免加载多余数据 ² 通过使用连接查询,配置二级缓存.查询缓存等方式减少select语句数目 ² 结合缓存机制,使用iterate()方法减少查询 ...
- Spring Boot的快速创建
一.利用向导快速搭建Spring Boot应用 创建一个controller package com.hoje.springboot.Controller; import org.springfram ...
- Leetcode 计划
如何正确高效地使用LeetCode? LeetCode按照怎样的顺序来刷题比较好? LeetCode 题目总结/分类 Leetcode 简略题解 - 共567题 500. Keyboard Row [ ...
- JSON 使用 教程
JSONP 教程 本章节我们将向大家介绍 JSONP 的知识. Jsonp(JSON with Padding) 是 json 的一种"使用模式",可以让网页从别的域名(网站)那获 ...
- struts2 上传下载文件,异常处理,数据类型转换
一,web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=" ...
- react阻止默认事件
return false无效 必须 preventDefault
- JavaScript--浅谈DOM操作
JavaScript之浅谈DOM操作 1.理解DOM: DOM(Document Object Model ,文档对象模型)一种独立于语言,用于操作xml,html文档的应用编程接口. 怎么说,我从两 ...
- ARCGIS知乎上的好文章
http://zhihu.esrichina.com.cn/?/feature/ArcGISAndroidDevNote ArcGIS知乎上有哪些干货可以推荐? http://zhihu.esrich ...
- leetCode题解之判断一个句子中的字符和数字是否构成回文
1.问题描述 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ...