Codeforces4D - Mysterious Present(LIS)
题目大意
给你一张宽为w,长为h的的贺卡,然后给你n个信封,每个信封宽为wi,长为hi,问你最多能在贺卡上嵌套多少个信封,如果某个信封i如果能够装在信封j里,当且仅当w[i]<w[j]&&h[i]<h[j]
题解
就是LIS嘛,没啥好说的。。。
代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define MAXN 5006
int pre[MAXN],dp[MAXN];
pair<pair<int,int>,int> a[MAXN];
void dfs(int x)
{
if(pre[x]!=-1) dfs(pre[x]);
printf("%d ",a[x].second+1);
}
int main()
{
int n,w,h;
scanf("%d%d%d",&n,&w,&h);
memset(pre,-1,sizeof(pre));
for(int i=0;i<n;i++)
{
scanf("%d%d",&a[i].first.first,&a[i].first.second);
a[i].second=i;
}
sort(a,a+n);
for(int i=0;i<n;i++)
{
if(w>=a[i].first.first||h>=a[i].first.second) continue;
dp[i]=1;
for(int j=0;j<i;j++)
if(a[i].first.first>a[j].first.first&&a[i].first.second>a[j].first.second&&dp[j]+1>dp[i])
{
dp[i]=dp[j]+1;
pre[i]=j;
}
}
int ans=max_element(dp,dp+n)-dp;
printf("%d\n",dp[ans]);
if(dp[ans])
{
dfs(ans);
printf("\n");
}
return 0;
}
Codeforces4D - Mysterious Present(LIS)的更多相关文章
- D. Mysterious Present (看到的一个神奇的DP,也可以说是dfs)
D. Mysterious Present time limit per test 2 seconds memory limit per test 64 megabytes input standar ...
- Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present 记忆化搜索
D. Mysterious Present 题目连接: http://www.codeforces.com/contest/4/problem/D Description Peter decided ...
- dp--C - Mysterious Present
C - Mysterious Present Peter decided to wish happy birthday to his friend from Australia and send hi ...
- Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present(LIS)
传送门 题意: 现在我们有 n 个信封,然后我们有一张卡片,并且我们知道这张卡片的长和宽. 现给出这 n 个信封的长和宽,我们想形成一个链,这条链的长度就是这条链中所含有的信封的数量: 但是需要满足① ...
- D - Mysterious Present
这个题和求最长递增序列的题类似,为了能输出一组可行的数据,我还用了一点儿链表的知识. Description Peter decided to wish happy birthday to his f ...
- codeforces mysterious present 最长上升子序列+倒序打印路径
link:http://codeforces.com/problemset/problem/4/D #include <iostream> #include <cstdio> ...
- Codeforces 4D Mysterious Present
http://codeforces.com/contest/4/problem/D 题目大意: 给出n个信封,这n个信封有长和宽,给出卡片的尺寸,求取能够装入卡片的最长的序列,序列满足后一个的长和宽一 ...
- 【Codeforces 4D】Mysterious Present
[链接] 我是链接,点我呀:) [题意] 要求长度和宽度都严格递增(选择一个序列) 然后你一开始有一个长度和宽度 要求这个一开始所给的长度和宽度能接在你选择的一段连续的长度宽度的开头 (且保持原来的性 ...
- D. Mysterious Present DAG dp
https://codeforces.com/problemset/problem/4/D 这个题目比较简单,就是一个DAG模型,这个可以看看紫书学习一下, 我这次是用dp来写的,用记忆化搜索也许更好 ...
随机推荐
- C++函数转换成C#函数
/// /// </param> /// <returns></returns> ...
- 一个简单的php分页类代码(转载)
入门级php分页类 原文地址:http://www.xfcodes.com/php/fenye/3608.htm 时间:2015-12-16 20:52:00来源:网络 php分页类. 复制代码代码如 ...
- css3 图标上下移动动画
@-webkit-keyframes bird{ 0% { -moz-transform: translate(0,0); -webkit-transform: translate(0,0); -o- ...
- BIOS
转自BIOS BIOS(Basic Input/Output System的缩写.中文:基本输入输出系统),在IBM PC兼容机上,是一种业界标准的固件接口.BIOS这个字眼是在1975第一次由CP/ ...
- FastCGI中文规范
http://fuzhong1983.blog.163.com/blog/static/1684705201051002951763/ . 介绍 FastCGI是对CGI的开放的扩展,它为所有因特网应 ...
- 10行Python代码解决约瑟夫环(模拟)
http://blog.csdn.net/dengyaolongacmblog/article/details/39208675 #!/usr/bin/env python # coding: utf ...
- Delphi编写自定义控件以及接口的使用(做了一个TpgDbEdit)
写给觉得自己编写Delphi很复杂的人,包括自己. Delphi自己写控件其实并不难,难的在于开发复杂的控件.(其实,编程,很多东西都是会了就不难,因此,我怕自己日后觉得自己写控件很难,特意在这记录自 ...
- Android 发送HTTP GET POST 请求以及通过 MultipartEntityBuilder 上传文件
折腾了好几天的 HTTP 终于搞定了,经测试正常,不过是初步用例测试用的,因为后面还要修改先把当前版本保存在博客里吧. 其中POST因为涉及多段上传需要导入两个包文件,我用的是最新的 httpmine ...
- freshStartTail 第一次启动时 抛弃旧的日志
freshStartTail [on/off] (requires v8.18.0+) Default: off This is used to tell rsyslog to seek to the ...
- jni数据问题
目的: jni中(c++函数)一个 char buf[4] 如何通过env->CallVoidMethod(clazz,method_OnFindCards,jStringParam); 在ap ...