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) ...
随机推荐
- php闭包简单实例
<?php function getClosure($i) { $i = $i.'-'.date('H:i:s'); return function ($param) use ($i) { ec ...
- 爬虫入门【3】BeautifulSoup4用法简介
快速开始使用BeautifulSoup 首先创建一个我们需要解析的html文档,这里采用官方文档里面的内容: html_doc = """ <html>< ...
- PAT 1061. 判断题(15)
判断题的评判很简单,本题就要求你写个简单的程序帮助老师判题并统计学生们判断题的得分. 输入格式: 输入在第一行给出两个不超过100的正整数N和M,分别是学生人数和判断题数量.第二行给出M个不超过5的正 ...
- SAP HR 复制PA30的人员
[转自http://www.512test.com/home/space.php?uid=19&do=blog&id=2381] 很多顾问测试HR的程序时都为录入人员头痛,下面的程序提 ...
- Windows下重置MySQL密码(最开始是因为Access denied for user 'root'@'localhost'这个原因,无法登陆 'root'@'localhost')
本人使用的MySQL5.5,其他版本未测试过. 方法一: 更改密码: mysql -u root -p Enter password:*** mysql>use mysql; 选择数据库 Dat ...
- Blobstore Java API overview
Blobstore API允许你的应用程序使用(serve)叫做Blobs的数据对象.这种数据对象比Datastore服务所允许的对象的尺寸大得多.Blobs能有效地为大文件比如视频.图片提供服务,允 ...
- 禁用chrome浏览器的cookie
Chrome: 1.打开chrome浏览器,点击右上角的“自定义和控制Google Chrome”按钮 2.在下拉菜单中选择设置 3.点击设置页底部的“显示高级设置...” 4.在隐私设置下,点击“内 ...
- linux shell 基础 使用日志与心得
linux shell 基础 使用日志与心得 1.#!/bin/bash 第一行就出现#!/bin/bash是指此脚本使用/bin/bash来解释执行.其中,#!是一个特殊的表示符,其后,跟着解释此脚 ...
- c/c++ 输入输出技巧
C: 小数的四舍五入问题 小数用 %.xf 输出的话 是会自动四舍五入的 比如说 double e = 2.718, c = 3.141; printf("%.2lf\n", e) ...
- HDU - 3081 Marriage Match II 【二分匹配】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3081 题意 有n对男女 女生去选男朋友 如果女生从来没和那个男生吵架 那么那个男生就可以当她男朋友 女 ...