【Codeforces 4D】Mysterious Present
【链接】 我是链接,点我呀:)
【题意】
要求长度和宽度都严格递增(选择一个序列)
然后你一开始有一个长度和宽度
要求这个一开始所给的长度和宽度能接在你选择的一段连续的长度宽度的开头
(且保持原来的性质)
问你这个最长序列是什么.并打印
【题解】
将信件按照w,h两个关键字分别上升的顺序排序
然后做个dp
f[i]表示以i作为开头能够得到的最长序列长度
并标记它下一个转移到了哪里
f[i] = max{f[j]+1} w[i]
【代码】
import java.io.*;
import java.util.*;
public class Main {
static InputReader in;
static PrintWriter out;
public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
}
static int N = (int)1e6;
static class Pair implements Comparable<Pair>{
int w,h,id;
public Pair(int w,int h,int id) {
this.w = w;
this.h = h;
this.id = id;
}
@Override
public int compareTo(Pair o) {
// TODO Auto-generated method stub
if (this.w!=o.w) {
return this.w-o.w;
}else {
return this.w-o.w;
}
}
}
static class Task{
static int N = 5000;
public void solve(InputReader in,PrintWriter out) {
int n,w0,h0;
n = in.nextInt();w0 = in.nextInt();h0 = in.nextInt();
Pair []a = new Pair[N+10];
int []f = new int[N+10];
int []nex = new int[N+10];
for (int i = 1;i <= n;i++) a[i] = new Pair(in.nextInt(),in.nextInt(),i);
Arrays.sort(a,1,n+1);
for (int i = n;i >= 1;i--) {
f[i] = 1;
nex[i] = i;
for (int j = i+1;j <= n;j++) {
if (a[j].h>a[i].h && a[j].w>a[i].w && f[j]+1>f[i]) {
f[i] = f[j]+1;
nex[i] = j;
}
}
}
int ans = 0;
int idx = 0;
for (int i = 1;i <= n;i++)
if (a[i].h>h0 && a[i].w>w0) {
if (f[i]>ans) {
ans = f[i];
idx = i;
}
}
out.println(ans);
for (int i = 1;i <= ans;i++) {
out.print(a[idx].id+" ");
idx = nex[idx];
}
}
}
static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer;
public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
}
public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
【Codeforces 4D】Mysterious Present的更多相关文章
- 【Codeforces 1009C】Annoying Present
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 其实就是让你最后这n个数字的和最大. 加上的x没有关系.因为肯定都是加上n个x 所以直接加上就可以了 主要在于如何选取j 显然我们要找到一个位 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【39.66%】【codeforces 740C】Alyona and mex
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【35.37%】【codeforces 556C】Case of Matryoshkas
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 758A】Holiday Of Equality
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【13.91%】【codeforces 593D】Happy Tree Party
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【26.67%】【codeforces 596C】Wilbur and Points
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 764B】Timofey and cubes
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 766C】Mahmoud and a Message
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- 2018.2.24Test总结
T1(luogu3434) comment:水题,考试时我想的是开一个数组在读入时预处理出该长度什么时候会被拦住,但这样数组开不下,剩下只能模拟. 实际上应该把圆筒变成递减序列,再二分该长度即可. T ...
- 使用免费SSL证书让网站支持HTTPS访问
参考掘金的文章,掘金的文章最详细. https://juejin.im/post/5a31cbf76fb9a0450b6664ee 先检查是否存在 EPEL 源: # 进入目录检查是否存在 EPEL ...
- Linux必知必会的目录结构
1.目录结构 /bin 二进制文件 命令 /sbin 超级命令 只有root用户可以使用 /boot 系统的引导文件 系统内核 /dev 设备文件 光盘 硬盘分区 /etc 系统配置文件 /home ...
- phpexecl 的基本操作
基本使用方法分三部分:一.引入接口 // PHPExcel_IOFactory require_once dirname(__FILE__).'/Classes/PHPExcel/IOFactory. ...
- 洛谷P1250种树(贪心)
题目描述 一条街的一边有几座房子.因为环保原因居民想要在路边种些树.路边的地区被分割成块,并被编号成1..N.每个部分为一个单位尺寸大小并最多可种一棵树.每个居民想在门前种些树并指定了三个号码B,E, ...
- Spring中常用的注解,你知道几个呢?
今天给大家分享下Spring中一般常用的注解都有哪些.可能很多人做了很长是了但有些还是不知道一些注解,不过没有关系,你接着往下看. Spring部分 1.声明bean的注解 @Component 组件 ...
- JQuery:常用知识点总结
jQuery本质上就是一个外部的js文件(jQuery.js),该文件中封装了很多js代码,实现了很多功能.并且jQuery有非常丰富的插件,大多数功能都有相应的插件解决方案.jQuery的宗旨是wr ...
- 【转】升级还是权谋?从USB PD 2.0到3.0
原文出处 http://www.eetop.cn/blog/html/43/n-433743.html 如同iPhone的出现,才让智能机真正主导手机市场一样,Type-C口发布后,USB PD才正式 ...
- js技巧(一)
1.文档入口函数 window.onload = function () { //code 将会在页面的全部代码执行完成之后再去执行. } 2.弹窗 alert() 警告窗 confirm ...
- Appium Python API 汇总
最近在学习Python自动化,网络搜集而来,留着备用, 方便自己也方便他人.感谢总结的人! 1.contexts contexts(self): Returns the contexts within ...