【51nod】1376 最长递增子序列的数量
第1行:1个数N,表示数组的长度。(1 <= N <= 50000)
第2 - N + 1行:每行1个数A[i],表示数组的元素(0 <= A[i] <= 10^9)
输出最长递增子序列的数量Mod 1000000007。
5
1
3
2
0
4
2 题解:nlogn树状数组维护,维护树状数组管辖区域内的最大值 c[i], 及该最大值相对应的最长上升子序列数量 dp[i].
#include<bits/stdc++.h>
using namespace std;
const int N = 5e4+, mod = ;
int a[N], b[N], c[N], dp[N];
void update(int n, int x, int y){
for(int i = n; i < N; i += i&-i){
if(c[i] < x)
c[i] = x, dp[i] = y;
else if(c[i] == x){
dp[i] += y;
if(dp[i] >= mod) dp[i] %= mod;
}
}
}
void get(int n, int& x, int& y){
x = y = ;
for(int i = n; i; i -= i&-i){
if(x < c[i])
x = c[i], y = dp[i];
else if(x == c[i]){
y += dp[i];
if(y >= mod) y %= mod;
}
}
} int main(){
int n; scanf("%d", &n);
for(int i = ; i < n; i++)
scanf("%d", a+i), b[i] = a[i];
sort(b, b+n);
for(int i = ; i < n; i++)
a[i] = lower_bound(b, b+n, a[i])-b+;
int x, y, ans = ;
for(int i = ; i < n; i++){
get(a[i]-, x, y);
x++;
update(a[i], x, x == ? : y);
}
get(n, x, ans);
printf("%d\n", ans);
return ;
}
【51nod】1376 最长递增子序列的数量的更多相关文章
- 51nod 1376 最长递增子序列的数量(线段树)
51nod 1376 最长递增子序列的数量 数组A包含N个整数(可能包含相同的值).设S为A的子序列且S中的元素是递增的,则S为A的递增子序列.如果S的长度是所有递增子序列中最长的,则称S为A的最长递 ...
- 51Nod 1376 最长递增子序列的数量 —— LIS、线段树
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1376 1376 最长递增子序列的数量 基准时间限制:1 秒 空 ...
- 51NOD 1376 最长递增子序列的数量 [CDQ分治]
1376 最长递增子序列的数量 首先可以用线段树优化$DP$做,转移时取$0...a[i]$的最大$f$值 但我要练习$CDQ$ $LIS$是二维偏序问题,偏序关系是$i<j,\ a_i< ...
- 51nod 1376 最长递增子序列的数量(不是dp哦,线段树 + 思维)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1376 题解:显然这题暴力的方法很容易想到就是以每个数为结尾最 ...
- 51Nod 1376 最长递增子序列的数量 (DP+BIT)
题意:略. 析:dp[i] 表示以第 i 个数结尾的LIS的长度和数量,状态方程很好转移,先说长度 dp[i] = max { dp[j] + 1 | a[i] > a[j] && ...
- 51nod 1376 最长上升子序列的数量 | DP | vector怒刷存在感!
51nod 1376 最长上升子序列的数量 题解 我们设lis[i]为以位置i结尾的最长上升子序列长度,dp[i]为以位置i结尾的最长上升子序列数量. 显然,dp[i]要从前面的一些位置(设为位置j) ...
- 51nod1376 最长递增子序列的数量
O(n2)显然超时.网上找的题解都是用奇怪的姿势写看不懂TAT.然后自己YY.要求a[i]之前最大的是多少且最大的有多少个.那么线段树维护两个值,一个是当前区间的最大值一个是当前区间最大值的数量那么我 ...
- 51nod 1134 最长递增子序列
题目链接:51nod 1134 最长递增子序列 #include<cstdio> #include<cstring> #include<algorithm> usi ...
- 51nod 1218 最长递增子序列 | 思维题
51nod 1218 最长递增子序列 题面 给出一个序列,求哪些元素可能在某条最长上升子序列中,哪些元素一定在所有最长上升子序列中. 题解 YJY大嫂教导我们,如果以一个元素结尾的LIS长度 + 以它 ...
随机推荐
- 配置SecondaryNameNode
一.SecondaryNameNode概念: 光从字面上来理解,很容易让一些初学者先入为主:SecondaryNameNode(snn)就是NameNode(nn)的热备进程.其实不是.ssn是HDF ...
- MySQL重置root用户密码的方法
本教程适用于采用Win2003.WinXP操作系统的迅美VPS和云主机产品. 当管理员忘记MySQL密码怎么办?屡次输入密码,仍然提示错误,网站无法正常运行,数据库也无法管理,管理员束手无策. 网站程 ...
- NSData NSDate NSString NSArray NSDictionary 相互转换
// NSData NSDate NSString NSArray NSDictionary json NSString *string = @"hello word"; NSDa ...
- smb.conf
[home]comment = All Printerspath = /homevalid users = yorkwriteable=yespublic=yesbrowseable = yescre ...
- texconv下载以及使用命令
包含texconv.exe,测试图片和测试批处理文件 命令: texconv.exe -ft DDS .\src\*.bmp -o .\output\ 下载: http://files.cnblogs ...
- Netfilter/iptables防火墙
http://os.51cto.com/art/201107/273443.htm [51CTO独家特稿]Linux系统管理员们都接触过Netfilter/iptables,这是Linux系统自带的免 ...
- MFC编程基础
http://www.cnblogs.com/lzmfywz/archive/2012/03/15/2399403.html 一.MFC类库概述 MFC(Microsoft Foundation cl ...
- MSSQL删除字段时出现 服务器: 消息 5074,级别 16,状态 1,行 1 的解决办法
有的朋友在做用户维护字段的界面时,肯定发现一个问题,当用脚本:ALTER TABLE 表名 DROP COLUMN 字段名进行删除字段的操作时,会出现“服务器: 消息 5074,级别 16,状态 1, ...
- 2016年12月12日 星期一 --出埃及记 Exodus 21:7
2016年12月12日 星期一 --出埃及记 Exodus 21:7 "If a man sells his daughter as a servant, she is not to go ...
- 2016年10月18日 星期二 --出埃及记 Exodus 19:2
2016年10月18日 星期二 --出埃及记 Exodus 19:2 After they set out from Rephidim, they entered the Desert of Sina ...