hdu1677 转换LIS
来源:互联网 发布:photoshop6 mac 编辑:程序博客网 时间:2024/06/06 02:37
题目大意:将小的布娃娃套进大的布娃娃总共需要多少个布娃娃。
思路:按宽度作为第一关键字升序排列,高度作为第二关键字降序排列,则高度的LIS就是所求的解。因为宽度是高到低,所以前面的必定能被LIS序列里面的某个数套进去,还有因为20 10不能套进20 10.所以在求LIS是不能用lower_bound(),因为lower_bound()求得是他所处位置但是在等于他本身那个数字的前面。所以要用upper_bound(),就可以了。。
#include <cstdio>#include <string>#include <cstring>#include <fstream>#include <algorithm>#include <cmath>#include <queue>#include <stack>#include <vector>#include <map>#include <set>#include <iostream>#include <iomanip>using namespace std;#define maxn 20055#define MOD 1000000007#define mem(a) memset(a , 0 , sizeof(a))#define memx(a) memset(a , 0x7f , sizeof(a))#define LL __int64#define INF 999999999struct node{ int w , h;}arr[maxn];int g[maxn];bool cmp(node n1 , node n2){ if(n1.w == n2.w) return n1.h < n2.h; else return n1.w > n2.w;}int main(){ int t; scanf("%d" , &t); while(t--) { int n ; scanf("%d" , &n); for(int i = 0 ; i < n ; i ++) scanf("%d %d" , &arr[i].w , &arr[i].h); sort(arr , arr + n , cmp); memx(g); int ans = 0; for(int i = 0 ; i < n ; i ++) { int k = upper_bound(g , g + n , arr[i].h) - g; g[k] = arr[i].h; ans = max(ans , k+1); } printf("%d\n" , ans); } return 0;}/*10430 10 20 13 20 14 20 15410 10 20 10 20 10 30 25410 15 20 10 20 30 30 25320 30 40 50 30 40420 30 10 10 30 20 40 50310 30 20 20 30 10410 10 20 30 40 50 39 51*/
0 0
- hdu1677 转换LIS
- Nested Dolls(hdu1677(LIS))
- hdu1677--Nested Dolls(贪心+LIS)
- HDU1677 Nested Dolls
- HDU1677:Nested Dolls
- hdu1677 Nested Dolls
- hdu1677(贪心+二分)
- BZOJ 4206 转换之后求LIS
- uva10635(LCS转换为求LIS)
- hdu1677 Nested Dolls(贪心)
- hdu1677 Nested Dolls Dilworth定理
- LIS
- LIS
- LIS
- LIS
- LIS
- LIS
- LIS
- matlab2013b 安装教程
- 读取xml文件和json文件
- 大话设计模式
- Android项目结构之模块内结构优化
- 【剑指offer】3.4代码的鲁棒性——面试题18:树的子结构
- hdu1677 转换LIS
- ios9后关于http协议问题
- 学习笔记06—电话拨号器
- [Volley+Gson]获取PM2.5小应用
- 【剑指offer】4.2画图让抽象问题形象化——面试题19:二叉树的镜像
- 5-11 分段计算居民水费
- Js cookie的用法详解
- 2016新年第一记
- Caffe傻瓜系列(9):训练和测试自己的图片