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 namesp…
D. Mysterious Present time limit per test 2 seconds memory limit per test 64 megabytes input standard input output standard output Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysteri…
D. Mysterious Present 题目连接: http://www.codeforces.com/contest/4/problem/D 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 i…
C - Mysterious Present 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…
传送门 题意: 现在我们有 n 个信封,然后我们有一张卡片,并且我们知道这张卡片的长和宽. 现给出这 n 个信封的长和宽,我们想形成一个链,这条链的长度就是这条链中所含有的信封的数量: 但是需要满足①信封a可以连接信封b当且仅当信封a的长和宽分别严格小于信封b的长和宽.       ②构成这条长链的所有信封的长和宽分别严格小于卡片的长和宽. 问最多可以形成多长的链,并且输出我们选取的链的编号: 题解: DAG上的动态规划: 如果信封对于任意两个信封 a,b 满足上述条件①②,那么连一条由a指向b…
这个题和求最长递增序列的题类似,为了能输出一组可行的数据,我还用了一点儿链表的知识. 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 …
link:http://codeforces.com/problemset/problem/4/D #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cctype> #include <algorithm> #include <queue> #include…
http://codeforces.com/contest/4/problem/D 题目大意: 给出n个信封,这n个信封有长和宽,给出卡片的尺寸,求取能够装入卡片的最长的序列,序列满足后一个的长和宽一定大于前一个,求最长的这个序列的长度,并且给出一组可行解. 思路:最长上升子序列 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<iostrea…
[链接] 我是链接,点我呀:) [题意] 要求长度和宽度都严格递增(选择一个序列) 然后你一开始有一个长度和宽度 要求这个一开始所给的长度和宽度能接在你选择的一段连续的长度宽度的开头 (且保持原来的性质) 问你这个最长序列是什么.并打印 [题解] 将信件按照w,h两个关键字分别上升的顺序排序 然后做个dp f[i]表示以i作为开头能够得到的最长序列长度 并标记它下一个转移到了哪里 f[i] = max{f[j]+1} w[i]<w[j] && h[i]<h[j] [代码] im…
https://codeforces.com/problemset/problem/4/D 这个题目比较简单,就是一个DAG模型,这个可以看看紫书学习一下, 我这次是用dp来写的,用记忆化搜索也许更好写一点. 这个首先进行建图,用一个邻接表建图,G[i][j]表示第i个信封可以装进去第j个信封,这个再建图之前需要排序. 不然的话就不好写这个dp了,其实这里有一点点不太能理解. 建完图之后就是dp的转移, dp[i]表示从第i个信封开始可以装的最多的信封 状态转移就是 d[i]=dp[j]+1 这…