#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define N 200
using namespace std;
int main()
{
int a[N]={0};
int b[N]={0};
int n;
int maxx;
int t=0;
while(scanf("%d",&n)!=EOF)
{
a[t]=n;
t++;
}
b[0]=1;
for(int i=1;i<t;i++)
{
b[i]=1;
for(int j=0;j<i;j++)
if(a[j]<a[i]&&b[j]+1>b[i])
b[i]=b[j]+1;
}
maxx=1;
for(int i=0;i<t;i++)
if(maxx<b[i])
maxx=b[i];
cout<<maxx<<endl;
return 0;
}
共 4 条回复
#include <bits/stdc++.h> #define up(l, r, i) for (int i = l, END##i = r; i <= END##i; ++i)
#define dn(r, l, i) for (int i = r, END##i = l; i >= END##i; --i)
using namespace std; typedef long long i64; const int INF = 2147483647; const int MAXN = 1e5 + 3; int n, t, H[MAXN], F[MAXN]; int main() { while (~scanf("%d", &H[++n])) ; --n; t = 0, memset(F, 0, sizeof(F)), F[0] = INF; up(1, n, i) { int l = 0, r = t + 1; while (r - l > 1) { int m = l + (r - l) / 2; if (F[m] >= H[i]) l = m; else r = m; } int x = l + 1; // dp[i] if (x > t) t = x; F[x] = H[i]; } t = 0, memset(F, 0, sizeof(F)), F[0] = 0; up(1, n, i) { int l = 0, r = t + 1; while (r - l > 1) { int m = l + (r - l) / 2; if (F[m] < H[i]) l = m; else r = m; } int x = l + 1; if (x > t) t = x; F[x] = H[i]; } printf("%d\n", t); return 0; }
#include<bits/stdc++.h> using namespace std; int n=1,a[10001],w=1,x; int main(){ while(scanf("%d",&x)){ a[n]=x,n++; } for(int i=2;i<=n;i++){ if(a[i]>a[i-1]){ w++; } } cout<<w; return 0; }
#define N 1010
#include using namespace std;
int main() { int n[1001], t[1001], i = 0, k = 0; while (cin >> n[i]) { i++; } t[0] = n[0]; for (int j = 1; j < i; j++) { bool f = 1; int wz; int max = 40000; for (int l = 0; l <= k; l++) { if (t[l] >= n[j] && t[l] < max) { f = 0; wz = l; max = t[l]; } } if (f) { k++; t[k] = n[j]; } else { t[wz] = n[j]; } } cout << k + 1; return 0; }