hoj 13969 Racing Gems

本文介绍了一种求解最长非降子序列问题的高效算法实现。通过输入一系列坐标点并进行转换,利用归并排序及动态规划思想,有效地找到了序列中最长的非递减子序列长度。
//最长非降子序列 感觉思维还是有点僵化哦 
#include <iostream> #include <algorithm> #include <stdio.h> #include <set> #include <queue> #include <cstring> #include <string> #include <limits.h> #include <string.h> #include <vector> #include <map> #define LL long long #define INF 2100000000 #define fi first #define se second #define lowbit(x) (x&(-x)) #define eps 5e-7 using namespace std; const int maxn=(int)1e5 +10; const int maxm=(int)2e4+10; const LL MOD=(LL)1e9+7; int n;LL r,w,h; LL a,b; struct nod{ LL x,y; void in(){ scanf("%I64d%I64d",&a,&b); x=b-r*a;y=b-r*(w-a); } }; bool cmp(const nod&a,const nod&b){ return (a.y==b.y&&a.x<b.x )||a.y<b.y; } nod f[maxn]; vector<LL> q; int main() { #ifdef shuaishuai freopen("C:\\Users\\hasee\\Desktop\\a.txt","r",stdin); //freopen("C:\\Users\\hasee\\Desktop\\b.txt","w",stdout); #endif scanf("%d%I64d%I64d%I64d",&n,&r,&w,&h); for(int i=0;i<n;i++) f[i].in(); sort(f,f+n,cmp); q.reserve(n); q.push_back(f[0].x); for(int i=1;i<n;i++){ if(q.back()<=f[i].x) q.push_back(f[i].x); else *upper_bound(q.begin(),q.end(),f[i].x)=f[i].x; } printf("%d\n",q.size()); return 0; }

 

转载于:https://www.cnblogs.com/MeowMeowMeow/p/7479638.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值