Description

A plotter is a vector graphics printing device that connects to a computer to print graphical plots. There are two types of plotters: pen plotters and electrostatic plotters. Pen plotters print by moving a pen across the surface of a piece of paper. They can draw complex line art, including text, but do so very slowly because of the mechanical movement of the pens. In this problem, we are considering this matter of slowness for our special type of pen plotter. A discrete horizontal pen plotter can draw only horizontal line segments whose end points have discrete coordinates (integer x and y’s). The drawing method is quite simple. The pen starts its journey from the upper left corner of the page (x=y=0) and moves only right while drawing the specified lines on that row. Then, it moves back completely to the left, moves one row down (y ← y+1), and repeats this task for the second row. The same is done for the next rows. In other words, the pen can move down only when it is far on the left side (i.e. when x=0), and can have at most one left-to-right pass and at most one right-to-left pass on each row. 
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

The input contains multiple test cases. Each test case starts with a line containing two integers n and t. The integer n is the number of line segments (n ≤ 1000) and t is the time-limit (t ≤ 106). Each of the next n lines specifies a line segment by giving three integers y, xs, and xt. Integer y indicates the row of that line segment (0 ≤ y ≤ 2000), and xs and xt are the x-coordinates of its end points (0 ≤ xs ≤ xt ≤ 106). The line segments are disjoint and do not have any intersections. A case of n = t = 0 shows the end of input and should not be processed.

Output

Write the result of the ith test case on the ith line of output. Each line should have only one integer, indicating the maximum number of line segments that can be drawn in its corresponding test case. 

题目大意:有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)的更多相关文章

  1. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  2. POJ - 2385 Apple Catching (dp)

    题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...

  3. POJ 1260:Pearls(DP)

    http://poj.org/problem?id=1260 Pearls Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8 ...

  4. POJ 2192 :Zipper(DP)

    http://poj.org/problem?id=2192 Zipper Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1 ...

  5. POJ 1191 棋盘分割(DP)

    题目链接 题意 : 中文题不详述. 思路 : 黑书上116页讲的很详细.不过你需要在之前预处理一下面积,那样的话之后列式子比较方便一些. 先把均方差那个公式变形, 另X表示x的平均值,两边平方得 平均 ...

  6. POJ 2533-Longest Ordered Subsequence(DP)

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 34454   Acc ...

  7. POJ 1018 Communication System(DP)

    http://poj.org/problem?id=1018 题意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m1.m2.m3.....mn个厂家提供生产,而每个厂家生产 ...

  8. POJ 2948 Martian Mining(DP)

    题目链接 题意 : n×m的矩阵,每个格子中有两种矿石,第一种矿石的的收集站在最北,第二种矿石的收集站在最西,需要在格子上安装南向北的或东向西的传送带,但是每个格子中只能装一种传送带,求最多能采多少矿 ...

  9. POJ 3280 Cheapest Palindrome(DP)

    题目链接 题意 :给你一个字符串,让你删除或添加某些字母让这个字符串变成回文串,删除或添加某个字母要付出相应的代价,问你变成回文所需要的最小的代价是多少. 思路 :DP[i][j]代表的是 i 到 j ...

随机推荐

  1. linux dentry cache 转自:http://blog.csdn.net/denzilxu/article/details/9188003

    Linux dentry cache学习 每个dentry对象都属于下列几种状态之一: (1)未使用(unused)状态:该dentry对象的引用计数d_count的值为0,但其d_inode指针仍然 ...

  2. Selenium处理页面---弹窗、表格、鼠标悬停、frame、下拉框、上传文件

    一.Selenium测试-常用页面处理 1.概述 UI自动化测试(GUI界面层):UI层是用户使用产品的入口,所有功能通过这一层提供给用户,测试工作大多集中在这一层,常见的测试工具有UFT.Robot ...

  3. Java的技术体系结构

    作为程序开发者,我们都想写出完美的代码,但世界上好像从来都没有过完美的代码,因为代码牵涉的内容很复杂,有程序设计语言.运行环境.数据结构以及算法等等,而开发者往往很难全面精通,再者写代码本来也就是一个 ...

  4. rm -f + 文件名+* 与 rm -f + 文件名* 的不同效果,大坑呀。

    rm -f catalina.2018-10-22.*    与*号间无空格 rm -f catalina.2018-10-22. *    :多了空格:

  5. etcd部署简单说明

    etcd是一个K/V分布式存储,每个节点都保存完成的一份数据.有点类似redis.但是etcd不是数据库. 1.先说废话.之所以会用etcd,并不是实际项目需要,而是前面自己写的上传的DBCacheS ...

  6. 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛--A-跳台阶

    链接:https://www.nowcoder.com/acm/contest/90/A 来源:牛客网 1.题目描述 小明在坐景驰科技研发的无人车到达了目的地. 景驰科技(JingChi.ai)是一家 ...

  7. CentOS 7 以上防火墙简单配置

    CentOS 7 版本以上默认的防火墙不是iptables,而是firewalle. 因此CentOS 7 以下的 iptables 的配置不能使用. 查看防火墙状态: systemctl statu ...

  8. Percona-Toolkit工具包之pt-archiver

      Preface       There's a common case that we neet to archive amount of records in some tables to a ...

  9. angular、angular2、vue的生命周期

    angular生命周期是什么 1.Angular每个组件都存在一个生命周期,从创建,变更到销毁.Angular提供组件生命周期钩子,把这些关键时刻暴露出来,赋予在这些关键结点和组件进行交互的能力,掌握 ...

  10. QQ群排名优化到霸屏的策略怎么做?

    谈起QQ群排名霸屏,首先要弄清楚概念,有些刚接触QQ群的朋友可能不太了解,所谓的QQ群排名霸屏,就是指当你的客户群体搜索QQ群某个关键词时,出现在QQ群搜索结果前面的群,全部或者大部分都是我们自己的群 ...