hdu 3998 Sequence
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).
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的更多相关文章
- HDU 3998 Sequence(经典问题,最长上升子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3998 解题报告:求一个数列的最长上升子序列,并求像这样长的不相交的子序列最多有多少个. 我用的是最简单 ...
- HDU 3998 Sequence (最长上升子序列+最大流)
参考链接:http://www.cnblogs.com/gentleh/archive/2013/03/30/2989958.html 题意:求一个序列的最长上升子序列,及其个数(注意:两个最长上升子 ...
- 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变 ...
- HDU 5919 Sequence II(主席树+逆序思想)
Sequence II Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) To ...
- hdu 5146 Sequence
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5146 Sequence Description Today we have a number sequ ...
- HDU 3998
http://acm.hdu.edu.cn/showproblem.php?pid=3998 求LIS的长度,并且求有多少组互不相交的LIS 求组数用最大流 建图如下: if(dp[i]==1)add ...
- HDU 6395 Sequence 【矩阵快速幂 && 暴力】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 5312 Sequence(数学推导——三角形数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5312 Sequence Time Limit: 2000/2000 MS (Java/Others) ...
- hdu 1711Number Sequence (KMP入门,子串第一次出现的位置)
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- python 之前函数补充(__del__, item系列, __hash__, __eq__) , 以及模块初体验
__str__ : str(obj) , 需求必须实现了 __str__, 要求这个方法的返回值必须是字符串 str 类型 __repr__ (意为原型输出): 是 __str__ 的备胎( ...
- Day 1 :成功完成注册
今天成功完成了cnblogs的注册,之后会在这里开业咯!记录下此刻时间
- NOIP考前划水
NOIP考前划水 君指先跃动の光は.私の一生不変の信仰に.唯私の超電磁砲永世生き! 要开始背配置了? 3行不谢. (setq c-default-style "awk") (glo ...
- 如何将cordova导入Android studio,只需两步即可
Cordova的技术交流新群 微信公众号:
- matlab 代码加速
~ 使用 parfor 代替 for 1. 安装 Parallel Computing Toolbox, 使用 parfor代替for, 使用的是cpu多核,速度能提高三倍左右. ~ 在for循环中的 ...
- sqlalchemy——多表操作
一对多:一对一 # one -- many class Students(Base): __tablename__ = "students" sid = Column(Intege ...
- HDU - 5695 Gym Class 【拓扑排序】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5695 思路 给定一些关系 进行拓扑排序 但是有一个要求 对于哪些没有确切的位置的点 要按照ID大小 I ...
- 让你快速上手Runtime(转)
前言 本篇主要介绍Runtime在开发中的一些使用场景,顺便讲解了下MJExtension的底层实现.如果喜欢我的文章,可以关注我微博:袁峥Seemygo,也可以来小码哥,了解下我们的iOS培训课程. ...
- 事件监听机制——鼠标事件MouseEvent
鼠标事件 鼠标事件包括鼠标的双击.左击.右击.中间键等等,本文进行事件加载进行简单介绍,具体可以参考键盘事件. import java.awt.*; import java.awt.event.*; ...
- MySQL 及 SQL 注入与防范方法
所谓SQL注入,就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令. 我们永远不要信任用户的输入,我们必须认定用户输入的数据都是不安全的, ...