• 【BZOJ】1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛(lis)


    http://www.lydsy.com/JudgeOnline/problem.php?id=1669

    水题太严重

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define rep(i, n) for(int i=0; i<(n); ++i)
    #define for1(i,a,n) for(int i=(a);i<=(n);++i)
    #define for2(i,a,n) for(int i=(a);i<(n);++i)
    #define for3(i,a,n) for(int i=(a);i>=(n);--i)
    #define for4(i,a,n) for(int i=(a);i>(n);--i)
    #define CC(i,a) memset(i,a,sizeof(i))
    #define read(a) a=getint()
    #define print(a) printf("%d", a)
    #define dbg(x) cout << #x << " = " << x << endl
    #define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
    inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
    inline const int max(const int &a, const int &b) { return a>b?a:b; }
    inline const int min(const int &a, const int &b) { return a<b?a:b; }
    bool cmp(int x, int y) { return x<=y; }
    int a[5005], f[5005], g[5005];
    int main() {
    	int n=getint(), ans=0;
    	for1(i, 1, n) read(a[i]);
    	CC(g, 0x7f);
    	for1(i, 1, n) {
    		int t=lower_bound(g+1, g+1+i, a[i], cmp)-g;
    		f[i]=t;
    		g[t]=a[i];
    		ans=max(ans, t);
    	}
    	print(ans);
    	return 0;
    }
    

    Description

    Farmer John养了N(1 <= N <= 5,000)头奶牛,每头牛都有一个不超过32位二进制数的正整数编号。FJ希望奶牛们在进食前,能按编号从小到大的顺序排好队,但奶牛们从不听他的话。 为了让奶牛们养成这个习惯,每次开饭时,FJ从奶牛中顺序地挑出一些,这些奶牛的编号必须按挑出的顺序递增。然后FJ让被挑出的奶牛们吃饭——其他奶牛就 只能饿肚子了。 现在,你得到了这一次开饭前队伍中从前到后所有奶牛的编号。奶牛们想请你计算一下,按照FJ的规定,最多有多少头奶牛能吃上饭? 比如说,有11头奶牛按以下顺序排好了队(数字代表奶牛的编号) 2 5 18 3 4 7 10 9 11 8 15 对于这个队列,最多可以让7头奶牛吃上饭,她们的编号分别为2,3,4,7,10,11,15。队列2,5,3,10,15是不合法的,因为第3头奶牛的 编号(3)小于她前面一头奶牛的编号(5)。

    Input

    * 第1行: 一个整数,N * 第2..?行: 除了最后一行,每一行都包含恰好20个用空格隔开的整数,依次表 示队伍中从前到后的奶牛的编号。如果N不能整除20,那么最后一 行包含的数字不到20个

    Output

    * 第1行: 输出按照FJ的规定,最多可以挑出的奶牛的数目

    Sample Input

    11
    2 5 18 3 4 7 10 9 11 8 15

    Sample Output

    7

    HINT

    Source

  • 相关阅读:
    在ubuntu下递归追索一个包的所有必要依赖项apt_dep.sh
    龙芯系统下,GTK与OPENGL共舞
    Linux应用程序自行开启Core Dump生成功能
    Daliy Algorithm -- day 102
    Daliy Algorithm -- day 101
    Daliy Algorithm -- day 100
    Daliy Algorithm -- day 99
    Daliy Algorithm -- day 98
    Daliy Algorithm -- day 97
    使用R语言进行简单的线性回归
  • 原文地址:https://www.cnblogs.com/iwtwiioi/p/3951985.html
Copyright © 2020-2023  润新知