首页 > 其他分享 >CodeForces 4D Mysterious Present(DP)

CodeForces 4D Mysterious Present(DP)

时间:2023-06-12 14:36:42浏览次数:33  
标签:chain int height width card envelopes Mysterious 4D DP


题意:你有一张长宽为x,y的卡片同时有n个盒子,长宽分别为xi,yi。然后问你卡片最多塞多少层盒子并且把这些盒子按照从里到外输出。

思路:由于数据给小了,所以n^2的DP也是可以水过的~



#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 5005;
int x[maxn],y[maxn],dp[maxn];
int p[maxn],n;
int dfs(int a)
{
	if (dp[a])
		return dp[a];
	for (int i =1 ;i<=n;i++)
	{
		if (x[a]<x[i] && y[a]<y[i])
			if (dfs(i)+1>dp[a])
			{
				p[a]=i;
				dp[a]=dfs(i)+1;
			}
	}
	return dp[a];
}
int main()
{
    scanf("%d",&n);
	for (int i = 0;i<=n;i++)
		scanf("%d%d",&x[i],&y[i]);
	int ans = dfs(0);
	printf("%d\n",ans);
	for (int i = p[0];i;i=p[i])
		printf("%d ",i);

}




Description



Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1,  a2,  ...,  an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i  -  1)-th envelope respectively. Chain size is the number of envelopes in the chain.

Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes.

Peter has very many envelopes and very little time, this hard task is entrusted to you.



Input



The first line contains integers nwh (1  ≤ n ≤ 5000, 1 ≤ w,  h  ≤ 106) — amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi — width and height of the i-th envelope (1 ≤ wi,  hi ≤ 106).



Output



In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers.

If the card does not fit into any of the envelopes, print number 0



Sample Input



Input



2 1 1 2 2 2 2



Output



1 1



Input



3 3 3 5 4 12 11 9 8



Output



3 1 3 2






标签:chain,int,height,width,card,envelopes,Mysterious,4D,DP
From: https://blog.51cto.com/u_16156555/6462537

相关文章

  • hdu2084数塔(DP)
    思路:简单的数塔DP#include<stdio.h>#include<string.h>#include<algorithm>usingnamespacestd;inta[105][105],dp[105][105];intmain(){intt,n,i,j;scanf("%d",&t);while(t--){scanf("%d",......
  • LightOJ 1422 Halloween Costumes (区间DP)
    题意:你要连续去很多个舞会,给出n个舞会你需要穿的衣服的编号,一旦脱下就不能再穿,但是可以一件套一件,问最少需要准备多少件衣服。思路:区间DP,令dp[i][j]为第i到第j天需要的衣服,那么对于第i天,如果考虑后面没有和它重复的话,那么dp[i][j]=dp[i+1][j]+1,如果存在某一天a[i]==a[k],dp[i][j]=......
  • HDU 5489 Removed Interval(DP)
    题意:求去掉某一个长度为L的子串的LIS思路:画画图其实比较显然的想法是去掉这个区间的时候答案是右边以第一个数开头的LIS+左边最后一个数小于右边第一个数的LIS,为什么是右边以第一个数开头的LIS呢,因为如果是在这个L的后第二个是最佳答案的话那么我在这个“窗口”滑到L+1这个位置的时......
  • HDU 5492 Find a path(DP)
    思路:将式子化开其实就是求(n+m-1)*s1-s2的最小值,s1表示各个格子的平方和,s2表示和的平方,留意到数据范围较小,令dp[i][j][k]为走到第i行第j列当前和为k的平方和的最小值,最后答案就是(n+m-1)*dp[i][j][k]-k*k#include<bits/stdc++.h>usingnamespacestd;#defineinf1e9inta[33][3......
  • TCP 协议快被淘汰了,UDP 协议才是新世代的未来?
    TCP协议可以说是今天互联网的基石,作为可靠的传输协议,在今天几乎所有的数据都会通过TCP协议传输,然而TCP在设计之初没有考虑到现今复杂的网络环境,当你在地铁上或者火车上被断断续续的网络折磨时,你可能都不知道这一切可能都是TCP协议造成的。本文会分析TCP协议为什么在弱网环......
  • 一文了解CDP
    传统营销模式下,我们越来越缺流量,流量也越来也贵;本质上,不是流量真的变少了,而是触点的碎片化,甚至粉末化;广告触达了一部分目标用户,或者顾客光临了店铺(无论线上或线下),已经产生了兴趣,甚至已有明确的意向,或者已经产生了消费,但是,我们既不知道这些用户具体是茫茫人海中哪一位,更无法主动再次......
  • C# 获取系统DPI缩放比例以及分辨率大小
    一般方法System.Windows.Forms.Screen类 //获取当前主屏幕分辨率 intscreenWidth=Screen.PrimaryScreen.Bounds.Width; intscreenHeight=Screen.PrimaryScreen.Bounds.Height;   //获取指定屏幕分辨率 ScreensecondaryScreen=Screen......
  • xrdp远程登陆服务器配置
    如何使用rdp远程Linux(CentOS)的图形化桌面原创 李德荣 EDA运维 2023-04-2721:57 发表于上海收录于合集#软件11个#服务器15个#电脑41个#IT50个#网络21个概述本篇文章以CentOS7.9和CentOSStream9为例,通过安装xrdp组件实现远程登陆实现方案......
  • SpringBoot自带ThreadPoolTaskScheduler实现数据库管理定时任务
    最近做了一个需求:将定时任务保存到数据库中,并在页面上实现定时任务的开关,以及更新定时任务时间后重新创建定时任务。于是想到了SpringBoot中自带的ThreadPoolTaskScheduler。在SpringBoot中提供的ThreadPoolTaskScheduler这个类,该类提供了一个schedule(Runnabletask,Triggert......
  • Java 网络编程 —— 基于 UDP 的数据报和套接字
    UDP简介UDP(UserDatagramProtocol,用户数据报协议)是传输层的另一种协议,比TCP具有更快的传输速度,但是不可靠。UDP发送的数据单元被称为UDP数据报,当网络传输UDP数据报时,无法保证数据报一定到达目的地,也无法保证各个数据报按发送的顺序到达目的地,例如:当发送方先发送包含字符......