【链接】 我是链接,点我呀:)

【题意】

要求长度和宽度都严格递增(选择一个序列)
然后你一开始有一个长度和宽度
要求这个一开始所给的长度和宽度能接在你选择的一段连续的长度宽度的开头
(且保持原来的性质)
问你这个最长序列是什么.并打印

【题解】

将信件按照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的更多相关文章

  1. 【Codeforces 1009C】Annoying Present

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 其实就是让你最后这n个数字的和最大. 加上的x没有关系.因为肯定都是加上n个x 所以直接加上就可以了 主要在于如何选取j 显然我们要找到一个位 ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【39.66%】【codeforces 740C】Alyona and mex

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【35.37%】【codeforces 556C】Case of Matryoshkas

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 758A】Holiday Of Equality

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【13.91%】【codeforces 593D】Happy Tree Party

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【26.67%】【codeforces 596C】Wilbur and Points

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 764B】Timofey and cubes

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【codeforces 766C】Mahmoud and a Message

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. B1068 [SCOI2007]压缩 区间dp

    这个题我状态想对了,但是转移错了...dp的代码难度都不大,但是思考含量太高了..不会啊,我太菜了. 其实这个题就是一个正常的区间dp,中间多了一个特判的转移就行了. 题干: Description ...

  2. 洛谷P2059 [JLOI2013]卡牌游戏

    题目描述 N个人坐成一圈玩游戏.一开始我们把所有玩家按顺时针从1到N编号.首先第一回合是玩家1作为庄家.每个回合庄家都会随机(即按相等的概率)从卡牌堆里选择一张卡片,假设卡片上的数字为X,则庄家首先把 ...

  3. openstack 杂记 备忘

  4. SceneView 追踪选择目标

    在编辑器的Scene视图中追踪选择目标,调试动作用 SceneView这个类没有说明文档比较蛋疼 在update中调用SceneViewCameraFace2Target函数,编辑器的OnInspec ...

  5. Oracle group by分组拼接字符串

    select wm_concat(id),depon  from test_1  group by depon

  6. MAC应用无法打开或文件损坏的处理方法

    在MAC下安装一些软件时提示"来自身份不明开发者",其实这是MAC新系统启用了新的安全机制.默认只信任 Mac App Store 下载的软件和拥有开发者 ID 签名的应用程序.换 ...

  7. ACM_Ruin of Titanic(简单贪心)

    Ruin of Titanic Time Limit: 2000/1000ms (Java/Others) Problem Description: 看完Titanic后,小G做了一个梦.梦见当泰坦尼 ...

  8. html用过标签记录

    nowrap="nowrap" //用于列表中td不许换行 maxlength="100" //用于输入框的长度限制 colspan="2" ...

  9. Android项目实战_手机安全卫士拦截骚扰

    ###1.骚扰拦截需求分析1.界面1.1 黑名单列表界面1.2 添加黑名单界面2.功能2.1 黑名单的添加.删除2.2 拦截电话2.3 拦截短信 ###2.黑名单数据库的创建1.分析需要的字段id 主 ...

  10. jQuery导航插件One-Page-Nav演示-显示命名锚记

    jQuery导航插件One-Page-Nav演示-显示命名锚记 简介 使用 选项 示例 推荐 简介 电商网站的分类比较明确,比如1楼是手机通讯产品,2楼是家用电器,3楼是服装鞋包等等,旁边还会有一个固 ...