POJ 3858 Hurry Plotter(DP)
Description
It takes one unit of time to move the pen one unit of length to the left (x ← x-1), or to the right (x ← x+1). This time is doubled if the pen is on the paper and is drawing a line segment. It takes no time to move one row down (when x=0).
Since it might take a long time for the plotter to draw all the given line segments, we have decided to add a new feature to our plotter: drawing time-limit. By specifying the time-limit, the plotter should draw the maximum number of lines (using the same drawing method given above) that can be drawn within that time-limit. Given the time-limit and line segments, you should find this maximum number.
Input
Output
题目大意:有n条水平的横线,每条横线都有一个纵坐标,和横线的开始横坐标和结束横坐标。现在有一支笔,要划这些线,这支笔只能从上往下移动,并且只能在x=0的地方从上往下移动。画横线的时候一定要从左到右画,画线移动的时间是普通移动时间的两倍。笔的每次横坐标移动花费时间为1,现在有时间限制t,问最多能画多少条线。
思路:先按y轴、y轴从小到大排序(即我们只能从序号小的移动到序号大的),然后dp[i][j]表示画到第 i 条横线,一共走过了 j 条横线,所花费的最小时间。然后每一个点不同步数找之前的可以走过来的点。暴力点时间复杂度为$O(n^3)$,不过貌似数据比较弱,n≤1000都秒过了。
代码(32MS):
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; const int MAXN = ; struct Node {
int y, st, ed;
void read() {
scanf("%d%d%d", &y, &st, &ed);
}
bool operator < (const Node &rhs) const {
if(y != rhs.y) return y < rhs.y;
return ed < rhs.ed;
}
}; int length(const Node &a, const Node &b) {
if(a.y == b.y) return b.st - a.ed;
return a.ed + b.st;
} Node a[MAXN];
int dp[MAXN][MAXN];
int n, t, ans; void solve() {
memset(dp, 0x3f, sizeof(dp));
ans = ;
for(int i = ; i <= n; ++i) {
if((dp[i][] = * a[i].ed - a[i].st) <= t) ans = max(ans, );
for(int j = ; j <= i; ++j) {
for(int k = j - ; k < i; ++k)
dp[i][j] = min(dp[i][j], dp[k][j - ] + length(a[k], a[i]));
dp[i][j] += * (a[i].ed - a[i].st);
if(dp[i][j] <= t) ans = max(ans, j);
}
}
} int main() {
while(scanf("%d%d", &n, &t) != EOF && n + t) {
for(int i = ; i <= n; ++i) a[i].read();
sort(a + , a + n + );
solve();
printf("%d\n", ans);
}
}
POJ 3858 Hurry Plotter(DP)的更多相关文章
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- POJ - 2385 Apple Catching (dp)
题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...
- POJ 1260:Pearls(DP)
http://poj.org/problem?id=1260 Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8 ...
- POJ 2192 :Zipper(DP)
http://poj.org/problem?id=2192 Zipper Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1 ...
- POJ 1191 棋盘分割(DP)
题目链接 题意 : 中文题不详述. 思路 : 黑书上116页讲的很详细.不过你需要在之前预处理一下面积,那样的话之后列式子比较方便一些. 先把均方差那个公式变形, 另X表示x的平均值,两边平方得 平均 ...
- POJ 2533-Longest Ordered Subsequence(DP)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 34454 Acc ...
- POJ 1018 Communication System(DP)
http://poj.org/problem?id=1018 题意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m1.m2.m3.....mn个厂家提供生产,而每个厂家生产 ...
- POJ 2948 Martian Mining(DP)
题目链接 题意 : n×m的矩阵,每个格子中有两种矿石,第一种矿石的的收集站在最北,第二种矿石的收集站在最西,需要在格子上安装南向北的或东向西的传送带,但是每个格子中只能装一种传送带,求最多能采多少矿 ...
- POJ 3280 Cheapest Palindrome(DP)
题目链接 题意 :给你一个字符串,让你删除或添加某些字母让这个字符串变成回文串,删除或添加某个字母要付出相应的代价,问你变成回文所需要的最小的代价是多少. 思路 :DP[i][j]代表的是 i 到 j ...
随机推荐
- 示例浅谈PHP与手机APP开发,即API接口开发
示例浅谈PHP与手机APP开发,即API接口开发 API(Application Programming Interface,应用程序接口)架构,已经成为目前互联网产品开发中常见的软件架构模式,并且诞 ...
- 《计算机图形学3D》
<计算机图形学方法原理应用> Opengl语言 光线跟踪 贝塞尔曲线 射线追踪 色彩理论 纹理映射 逆向运动 MPI 仿射 绘制流水线 透视变换 bre ...
- 分布式id生成
2016年08月09日 14:15:21 yuanyuanispeak 阅读数:318 编辑 一.需求缘起 几乎所有的业务系统,都有生成一个记录标识的需求,例如: (1)消息标识:message-id ...
- JS基础——数组API之数组操作(filter、map、some、every、sort)
var arr = [1,2,3,4]; forEach arr.forEach((item,index,arr) => { console.log(item) //结果为1,2,3,4 } ...
- spring boot 搭建基本套路《1》
1. Spring复习 Spring主要是创建对象和管理对象的框架. Spring通过DI实现了IoC. Spring能很大程度的实现解耦. 需要掌握SET方式注入属性的值. 需要理解自动装配. 需要 ...
- html样式不兼容 详解(转)
网站对火狐不兼容的原因以及解决的方法 1.DOCTYPE 影响 CSS 处理 2.FF: div 设置 margin-left, margin-right 为 auto 时已经居中, IE 不行 3. ...
- weex踩坑记录
weex框架样式问题--我暂时使用最基本的样式css,weex前端开发的话web端会显示各种的html标签.写出的样式也都会显示的很好,但是在app端的话,就没有很好的兼容性,只是支持文档中的一些标签 ...
- HTML5+ MUI实现ajax的一个demo
index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> &l ...
- 微信小程序横向滚动
<scroll-view scroll-x="true" style=" white-space: nowrap; display: flex" > ...
- Matplotlib 子图的创建
在matplotlib中,整个图像为一个Figure对象 在Figure对象中可以包含一个或者多个Axes对象 每个Axes对象相当于一个子图了 每个Axes(ax)对象都是一个拥有自己坐标系统的绘 ...