标签:memset span print sizeof play main col closed pen
存个板子 只能求长度 不知道具体序列
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fi first #define se second #define all(a) (a).begin(), (a).end() #define fillchar(a, x) memset(a, x, sizeof(a)) #define huan printf("\n"); using namespace std; typedef long long ll; const int maxn=1e5+20,maxm=100,inf=0x3f3f3f3f; const ll mod=1000000007; int n,d[100005],a[100005]; int main() { //--------------------------最长不上升--------------------------------------------------- scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%d",&a[i]); d[1]=-a[1]; int len=1; for(int i=2; i<=n; i++) { if(-a[i]>=d[len]) d[++len]=-a[i]; else { int pos=upper_bound(d+1,d+len,-a[i])-d; d[pos]=-a[i]; } } printf("%d\n",len); /*--------------------------最长不下降-------------------------------------------------------- scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%d",&a[i]); d[1]=a[1]; //初始化 int len=1; for (int i=2; i<=n; i++) { if (a[i]>=d[len]) d[++len]=a[i]; //如果可以接在len后面就接上,如果是最长上升子序列,这里变成> else //否则就找一个最该替换的替换掉 { int pos=upper_bound(d+1,d+len+1,a[i])-d; //找到第一个大于它的d的下标,如果是最长上升子序列,这里变成lower_bound d[pos]=a[i]; } } printf("%d\n",len); */ }
标签:memset span print sizeof play main col closed pen
原文地址:https://www.cnblogs.com/stranger-/p/9565567.html