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

【题意】

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

【题解】

将信件按照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. 【POJ 1716】 Integer Intervals

    [题目链接] 点击打开链接 [算法] 差分约束系统 [代码] #include <algorithm> #include <bitset> #include <cctyp ...

  2. El Dorado(dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=2372 题意:给出n个数,求长度为m的递增子序列的数目. 思路:状态转移方程 dp[i][j] = sum(dp[ ...

  3. php phppowerpoint

    今天早上从订阅的 Zend DevZone 看到篇很有意思的文章. Creating PowerPoint 2007 files using PHP. 试了一下. 果然很又意思, 分享给大家吧. 程序 ...

  4. js判断ie6的代码

    var isIE=!!window.ActiveXObject; var isIE6=isIE&&!window.XMLHttpRequest; var isIE8=isIE& ...

  5. codevs4511信息传递(Tarjan求环)

    题目描述 有n个同学(编号为1到n)正在玩一个信息传递的游戏.在游戏里每人都有一个固定的信息传递对象,其中,编号为i的同学的信息传递对象是编号为Ti同学. 游戏开始时,每人都只知道自己的生日.之后每一 ...

  6. [App Store Connect帮助]二、 添加、编辑和删除用户(5)创建一个沙盒测试员帐户

    如果您的 App 使用了 App 内购买项目或 Apple Pay,您可以在 App Store Connect 中创建沙盒测试员帐户,以便您向用户提供该 App 前,可以使用该帐户在测试环境中运行您 ...

  7. [Apple开发者帐户帮助]九、参考(5)支持的功能(tvOS)

    tvOS应用程序可用的功能取决于您的程序成员身份. 能力 ADP 企业 Apple开发者 应用程序组 相关域名   背景模式 数据保护 游戏中心     游戏控制器 HomeKit iCloud:Cl ...

  8. [Swift通天遁地]五、高级扩展-(14)扩展String快速计算字符串中的各种数学表达式

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  9. Sorting It All Out 拓扑排序+确定点

    这一道题的话  数据有一点问题    ........     例如 不过 还是   能理解一下  试试吧  ......... A<B B<C C<A A<C B<A ...

  10. CSS------选择器-----------选择器的分组、属性选择器

    /*!--选择器的分组--*/ .groupDiv h1,h2,h3,h4{ color: #000000; } /*------------------------属性选择器--*/ [title] ...