zoukankan      html  css  js  c++  java
  • bzoj1669[Usaco2006 Oct]Hungry Cows饥饿的奶牛*

    bzoj1669[Usaco2006 Oct]Hungry Cows饥饿的奶牛

    题意:

    求最长单调递增子序列,序列大小≤5000

    题解:

    蒟蒻弱写了一个O(n^2)的。

    代码:

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 #define inc(i,j,k) for(int i=j;i<=k;i++)
     5 #define maxn 5100
     6 using namespace std;
     7 
     8 inline int read(){
     9     char ch=getchar(); int f=1,x=0;
    10     while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
    11     while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    12     return f*x;
    13 }
    14 int a[maxn],f[maxn],n;
    15 int main(){
    16     n=read(); inc(i,1,n)a[i]=read();
    17     inc(i,1,n){
    18         f[i]=1; inc(j,1,i-1)if(a[j]<a[i])f[i]=max(f[i],f[j]+1);
    19     }
    20     inc(i,1,n)f[0]=max(f[0],f[i]); printf("%d",f[0]); return 0;
    21 }

    20160808

  • 相关阅读:
    poj 1010
    poj 1060
    poj 1001
    POJ 2769
    POJ 2559
    poj 2403
    POJ 1088
    设置全屏与退出全屏
    iframe 父子页面方法调用
    Web 前端面试小知识
  • 原文地址:https://www.cnblogs.com/YuanZiming/p/5767342.html
Copyright © 2011-2022 走看看