[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 – ...
随机推荐
- 数组的strong copy理解
一.数组的不同情况下的copy,mutablecopy分析 1.不可变数组的copy(没有创建新对象,复制的只是指针) 2.不可变数组的mutable copy(创建新对象) ...
- static dictionary methods of text compression
Now I will introduce a way to compress a text. When we are confronted with numerous data, and the da ...
- 高并发第十一弹:J.U.C -AQS(AbstractQueuedSynchronizer) 组件:Lock,ReentrantLock,ReentrantReadWriteLock,StampedLock
既然说到J.U.C 的AQS(AbstractQueuedSynchronizer) 不说 Lock 是不可能的.不过实话来说,一般 JKD8 以后我一般都不用Lock了.毕竟sychronize ...
- Centos7 安装 ActiveMq
1.安装 # cd /usr/local/src/# wget http://mirrors.shu.edu.cn/apache//activemq/5.15.3/apache-activemq-5. ...
- C#(简单递归)和实现IComparable接口
递归: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...
- Jquery使用Id获取焦点和失去焦点
Jquery使用Id获取焦点和失去焦点有2种方法 先用第一种(val()=="空"): <div> <input type="text" id ...
- redis安装以及php扩展
启动安装: http://elain.blog.51cto.com/3339379/705846 redis下载: https://github.com/nicolasff/phpredis/do ...
- Android开发问题积累 <加载在线Gif><WebView无法加载网页图片>
在线Gif加载 解决办法 Glide完美解决 Glide.with(context).load(pic).placeholder(R.drawable.loading).into(imageView) ...
- 网络I/O模型--06异步I/O
异步I/O (又称为 AIO )则是采用“订阅一通知”工作模式 : 即应用程序向操作系统注册I/O监听,然后继续做自己的事情.当操作系统发生I/O事件,并且准备好数据后 , 再主动通知应用程序,触发相 ...
- Spring Boot—19Cache
pom.xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...