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. php闭包简单实例

    <?php function getClosure($i) { $i = $i.'-'.date('H:i:s'); return function ($param) use ($i) { ec ...

  2. hdu_吃糖果(思维题)

    吃糖果 Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submiss ...

  3. Java编码规范之数据对象命名

    数据对象分多种,为方便阅读并区分各数据对象的用途,习惯将数据对象分为以下几类,供参考: 持久对象 PO(persistant object)对象关系映射(ORM)概念的产物,基本上对象的成员变量对应了 ...

  4. ShowModal 代码分析

    下面为Delphi中,方法TCustomForm.ShowModal的代码,通过分析以下代码,可以了解ShowModal到底是怎么一回事! 1 2 3 4 5 6 7 8 9 10 11 12 13 ...

  5. Unity 武器拖尾效果

    Pocket RPG Weapon Trails 武器拖尾效果 Asset Store地址:https://www.assetstore.unity3d.com/en/#!/content/2458 ...

  6. cordova 获取地理位置

    第一步,引入插件 cordova plugin add cordova-plugin-geolocation 第二步, <!DOCTYPE html> <html> <h ...

  7. migrate

    数据类型 引用 # :string, :text, :integer, :float,:decimal, :datetime, :timestamp, :time, :date, # :binary, ...

  8. Kattis - names Palindrome Names 【字符串】

    题目链接 https://open.kattis.com/problems/names 题意 给出一个字符串 有两种操作 0.在字符串的最末尾加一个字符 1.更改字符串中的一个字符 求最少的操作步数使 ...

  9. Hadoop如何修改HDFS文件存储块大小

    一. 临时修改可以在执行上传文件命令时,显示地指定存储的块大小.1. 查看当前 HDFS文件块大小我这里查看HDFS上的TEST目录下的jdk-7u25-linux-x64.gz  文件存储块大小.1 ...

  10. Oracle数据库体系结构(1)整体概述

    oracle数据库的存储结构: 逻辑存储结构:oracle内部的组织和管理数据的方式 物理存储结构:oracle外部(操作系统)组织和管理数据的方式 oracle对逻辑存储结构和物理存储结构的管理是分 ...