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) ...
随机推荐
- sql server 2008 去除html标签
由于商品详情数据库的字段是text,存放的是html,但是要求导出的商品详情中只是商品的描述,不要标签,原来打算先把数据导入excel中,然后利用java的正则去替换,结果由于商品详情太大,一个单元格 ...
- api签名认证
参数列表: data: { sign, uid或是openId, version, timestamp, param } sign 签名一般情况下,根据如下几项生成,通过md5或是aes加密: 接口 ...
- MySQL 练习 答案
表关系 二.操作表 1.自行创建测试数据 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 3.查询平均成绩大于60分的同学的学号和平均成绩: 4.查询所有同学的学号.姓名.选课数.总成绩: ...
- Linux shell join命令详解
Linux join命令 2012-02-09 17:49:00| 分类: SHELL | 标签:linux join 文件连接 |字号 订阅join命令 功能:“将两个文件里指定栏位同样的行连接起来 ...
- 通过systemd配置Docker
1. systemd Service相关目录 通常情况下,我们有3种方式可以配置etcd中的service.以docker为例,1)在目录/etc/systemd/system/docker.serv ...
- 【整理学习Hadoop】Hadoop学习基础之一:服务器集群技术
服务器集群就是指将很多服务器集中起来一起进行同一种服务,在客户端看来就像是只有一个服务器.集群可以利用多个计算机进行并行计算从而获得很高的计算速度,也可以用多个计算机做备份,从而使得任 ...
- 小程序获取openid和unionid java实现
官方api:https://developers.weixin.qq.com/miniprogram/dev/api/api-login.html#wxloginobject 参考文章:https:/ ...
- vim终端配色(非gui版本)——Monokai
啥也别说,先上图. 具体配置: 1. 将molokai.vim文件(下面贴出)放到 ~/.vim/colors 目录下,如没有此文件夹需自行创建. 提示:~ 代表用户主目录,如我的用户名是 akaed ...
- ubuntu14.04 安装pip vitualenv flask
安装pip: $ apt-get install python-pip$ pip -V #查看版本 确认安装成功 安装完pip后,会发现下载的速度特别慢.按如下修改: $ vim ~/.pip/pip ...
- Data Structure Binary Tree: Convert a given Binary Tree to Doubly Linked List
http://www.geeksforgeeks.org/in-place-convert-a-given-binary-tree-to-doubly-linked-list/ #include &l ...