There is a sequence X (i.e. x[1], x[2], ..., x[n]). We define increasing subsequence of X
as x[i1], x[i2],...,x[ik], which satisfies follow conditions:

1) x[i1] < x[i2],...,<x[ik];

2) 1<=i1 < i2,...,<ik<=n

As an excellent program designer, you must know how to find the maximum length of the

increasing sequense, which is defined as s. Now, the next question is how many increasing

subsequence with s-length can you find out from the sequence X.

For example, in one case, if s = 3, and you can find out 2 such subsequence A and B from X.

1) A = a1, a2, a3. B = b1, b2, b3.

2)
Each ai or bj(i,j = 1,2,3) can only be chose once at most.

Now, the question is:

1) Find the maximum length of increasing subsequence of X(i.e. s).

2) Find the number of increasing subsequence with s-length under conditions described (i.e. num).

InputThe input file have many cases. Each case will give a integer number n.The next line will

have n numbers.OutputThe output have two line. The first line is s and second line is num.Sample Input

4
3 6 2 5

Sample Output

2
2 最长上升子序列。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
#define Max 1000
using namespace std;
int n,s[Max],vis[Max];///vis标记是否已经使用
int maxl()
{
int res = ,t[Max];
for(int i = ;i < n;i ++)
{
if(vis[i])continue;
if(!res || t[res - ] < s[i])
{
t[res ++] = s[i];
vis[i] = ;
}
else
{
// *lower_bound(t,t + res,s[i]) = s[i];
int l = ,r = res,mid;
while(l < r)
{
mid = (l + r) / ;
if(t[mid] >= s[i])r = mid;
else l = mid + ;
}
t[l] = s[i];
}
}
return res;
}
int main()
{
while(scanf("%d",&n) != EOF)
{
for(int i = ;i < n;i ++)
{
scanf("%d",&s[i]);
}
memset(vis,,sizeof(vis));
int m = maxl(),c = ;
while(maxl() == m)c ++;
printf("%d\n%d\n",m,c);
}
}

hdu 3998 Sequence的更多相关文章

  1. HDU 3998 Sequence(经典问题,最长上升子序列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3998 解题报告:求一个数列的最长上升子序列,并求像这样长的不相交的子序列最多有多少个. 我用的是最简单 ...

  2. HDU 3998 Sequence (最长上升子序列+最大流)

    参考链接:http://www.cnblogs.com/gentleh/archive/2013/03/30/2989958.html 题意:求一个序列的最长上升子序列,及其个数(注意:两个最长上升子 ...

  3. HDU 3397 Sequence operation(线段树)

    HDU 3397 Sequence operation 题目链接 题意:给定一个01序列,有5种操作 0 a b [a.b]区间置为0 1 a b [a,b]区间置为1 2 a b [a,b]区间0变 ...

  4. HDU 5919 Sequence II(主席树+逆序思想)

    Sequence II Time Limit: 9000/4500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) To ...

  5. hdu 5146 Sequence

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5146 Sequence Description Today we have a number sequ ...

  6. HDU 3998

    http://acm.hdu.edu.cn/showproblem.php?pid=3998 求LIS的长度,并且求有多少组互不相交的LIS 求组数用最大流 建图如下: if(dp[i]==1)add ...

  7. HDU 6395 Sequence 【矩阵快速幂 && 暴力】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others)   ...

  8. hdu 5312 Sequence(数学推导——三角形数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5312 Sequence Time Limit: 2000/2000 MS (Java/Others)  ...

  9. hdu 1711Number Sequence (KMP入门,子串第一次出现的位置)

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. LR报错 No buffer space available Try changing the registry value 端口号不够用了

    报错:Action.c(6): Error -27796: Failed to connect to server "10.16.137.8:10035": [10055] No ...

  2. centos7.0 安装pdo_mysql扩展

    1:进入到源码包 /usr/local/php-7.1.6/ext/pdo_mysql 执行/usr/local/php-7.1/bin/phpize 如果报如下错误: Cannot find aut ...

  3. lua例子(进出栈)

    #include <stdio.h> extern "C" { #include "lua-5.2.2/src/lauxlib.h" #includ ...

  4. 计算点与x轴正半轴夹角atan2(double y,double x),返回弧度制(-PI,PI]

    精度比acos , asin 什么的高些. Parameters y Value representing the proportion of the y-coordinate. x Value re ...

  5. web.xml配置整理

    虽然是做web开发,但是web中的很多配置有的时候却不是很清楚,只是知道怎么配置,于是就把在网上看到各种关于web.xml的东西整理一下: web.xml中url-pattern的3种写法 1完全匹配 ...

  6. mysql中的乐观锁和悲观锁

    mysql中的乐观锁和悲观锁的简介以及如何简单运用. 关于mysql中的乐观锁和悲观锁面试的时候被问到的概率还是比较大的. mysql的悲观锁: 其实理解起来非常简单,当数据被外界修改持保守态度,包括 ...

  7. Python小练习(持续更新....)

    最近一直在学习python,这些小练习有些是书上的,有些是别人博客上的! # 1.题目1# 给一个字符串,统计其中的数字.字母和其他类型字符的个数:# 比如输入“124mid-=”,输出:数字=3,字 ...

  8. 【题解】P2161[SHOI2009]会场预约(set)

    [题解][P2161 SHOI2009]会场预约 题目很像[[题解]APIO2009]会议中心 \(set\)大法好啊! 然后我们有个小\(trick\)(炒鸡帅),就是如何优雅地判断线段交? str ...

  9. LeetCode:验证回文串【125】

    LeetCode:验证回文串[125] 题目描述 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 示例 1: 输入: ...

  10. 吴恩达机器学习笔记(四) —— BP神经网络

    主要内容: 一.模型简介 二.一些变量所代表的含义 三.代价函数 四.Forward Propagation 五.Back Propagation 六.算法流程 待解决问题: 视频中通过指出:当特征变 ...