裸的LIS

-----------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
 
#define rep( i , n ) for( int i = 0 ;  i < n ; ++i )
#define clr( x , c ) memset( x , c , sizeof( x ) )
 
using namespace std;
 
const int maxn = 5000 + 5;
const int inf = 0x7fffffff;
  

int seq[ maxn ];

int g[ maxn ];
 
int main() {
// freopen( "test.in" , "r" , stdin );
int n;
cin >> n;
rep( i , n ) g[ i ] = inf;
int ans = 0;
rep( i , n ) {
   int x;
   
   scanf( "%d" , &x );
   
   int t = lower_bound( g , g + n , x ) - g;
   
   ans = max( t + 1 , ans );
   
   g[ t ] = x;
   
}
cout << ans << "\n";
return 0;
}

-----------------------------------------------------------------

1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 739  Solved: 466
[Submit][Status][Discuss]

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

BZOJ 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛( LIS )的更多相关文章

  1. bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛【dp+树状数组+hash】

    最长上升子序列.虽然数据可以直接n方但是另写了个nlogn的 转移:f[i]=max(f[j]+1)(a[j]<a[i]) O(n^2) #include<iostream> #in ...

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

    http://www.lydsy.com/JudgeOnline/problem.php?id=1669 水题太严重 #include <cstdio> #include <cstr ...

  3. BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛

    1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 665  Solved: 419 ...

  4. 【动态规划】bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛

    #include<cstdio> #include<algorithm> using namespace std; int n,a[5001],b[5001],en; int ...

  5. 「BZOJ1669」D 饥饿的牛 [Usaco2006 Oct] Hungry Cows 牛客假日团队赛5 (LIS,离散化树状数组)

    链接:https://ac.nowcoder.com/acm/contest/984/D 来源:牛客网 饥饿的牛 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言 ...

  6. bzoj:1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏

    Description 奶牛们又在玩一种无聊的数字游戏.输得很郁闷的贝茜想请你写个程序来帮她在开局时预测结果.在游戏的开始,每头牛都会得到一个数N(1<=N<=1,000,000).此时奶 ...

  7. bzoj 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏【模拟】

    模拟 #include<iostream> #include<cstdio> using namespace std; int n,ans; int main() { scan ...

  8. BZOJ 1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 幼儿园测试题

    本来以为是一道数学题,一顿XJBT导式子,结果就是个幼儿园都会的模拟. Code: #include<bits/stdc++.h> #define ll long long using n ...

  9. BZOJ1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏

    1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 5 ...

随机推荐

  1. asp.net 多站点共享StateServer Session

    <sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" ...

  2. linux下如何查看系统和内核版本

        1. 查看内核版本命令: 1) [root@q1test01 ~]# cat /proc/version Linux version 2.6.9-22.ELsmp (bhcompile@cro ...

  3. Delphi中Android运行和JNI交互分析

    Androidapi.JNIBridge负责和JNI交互.,既然要交互,那么首先就是需要获得JNI的运行环境,Android本身内置的就有一个Java(Dalvik)虚拟机.所以这个第一步就肯定是要这 ...

  4. HDU 5741 Helter Skelter(构造法)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5741 [题目大意] 一个01相间的串,以0开头,给出的序列每个数字表示连续的0的个数或者1的个数, ...

  5. oracle db_unnqiue_name db_name sid_name instance_name service_name

  6. 解决phpmyadmin-1800秒超时链接失效问题

    在phpmyadmin的配置文件里 \usr\share\phpMyAdmin\libraries\config.default.php 修改 $cfg[‘LoginCookieValidity’] ...

  7. iOS搜索指定字符在字符串中的位置

    NSString *tmpStr = @"asd341234aaaaccd"; NSRange range; range = [tmpStr rangeOfString:@&quo ...

  8. Tomcat 的context.xml

    1. 在tomcat 5.5之前: --------------------------------------------------------------- Context体如今/conf/se ...

  9. Objective-c 字典对象

    oc 中的 NSDictionary 的作用同 java 中的字典类相同,提供了 “键-值”对的组合.比如,是用字典类实现对学生姓名和学号的存放,编号是一个键(唯一性),姓名是值.它的方法有: 下面通 ...

  10. 密码输入模块getpass

    getpass模块用于命令行输入密码,它提供了两个函数.         getpass.getpass([prompt[, stream]])         提示用户输入密码,同时不显示输入的密码 ...