【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 ...
随机推荐
- 51nod 1406 与查询
垃圾选手练dp 考虑对于一个数,能够把它表示出来也一定可以把它某些1的位变成0变成的数表示出来 那么用大的数更新小的,容易想到每次都把这个大的数的1个1的位变成0 但是这样还是会有重复的情况 比如10 ...
- NOI.AC #31. MST
好像又是神仙dp....gan了一早上 首先这是个计数类问题,上DP, 对于一个最小生成树,按照kruskal是一个个联通块,枚举边小到大合成的 假如当前边是树边,那么转移应该还是枚举两个块然后合并 ...
- C# 数据库访问
C# 数据库访问 分类: C#学习笔记2011-07-05 11:26 515人阅读 评论(0) 收藏 举报 数据库c#datasettextboxcommandexception 目录(?)[+ ...
- [bzoj3274]Circle
https://www.zybuluo.com/ysner/note/1243396 题面 有\(n\)个排成一圈的格子,并且已知正整数\(k\)和\(m\),你需要往每个格子中填入一个大于等于\(k ...
- PCB ODB++(Gerber)图形绘制实现方法
这里讲解一下用net解析PCB图形绘制实现方法 一.解析PCB图形绘制实现 解析PCB图形,说简单也非常简单,先说一下,PCB Gerber图形由:点,线,弧,铜皮,文字 5类元素组成,通常简写为:P ...
- E20170926-mk
validation n. 确认; proposal n. 建议; 提议; 求婚; 〈美〉投标; teaser n. 戏弄者,喜欢戏弄别人的人; 棘手的问题; batch n. 一批; 一 ...
- StreamingListener技术点
以下是对StreamingListene的研究,由于比较简单,故只贴代码,不做解释 /** * Created by gabry.wu on 2016/5/27. * 实现StreamingListe ...
- linux 防火墙关闭
systemctl status firewalld.servicesystemctl status iptables.service关闭防火墙,selinux15:54:43运维-李浩 2017/ ...
- 342 Power of Four 4的幂
给定一个整数 (32位有符整数型),请写出一个函数来检验它是否是4的幂.示例:当 num = 16 时 ,返回 true . 当 num = 5时,返回 false.问题进阶:你能不使用循环/递归来解 ...
- 324 Wiggle Sort II 摆动排序 II
给定一个无序的数组nums,将它重新排列成nums[0] < nums[1] > nums[2] < nums[3]...的顺序.例子:(1) 给定nums = [1, 5, 1, ...