51nod1376 最长上升子序列的数量


机房的人问我树状数组怎么做这题......
树状数组维护$len, num$表示$LIS$的长度和数量即可
复杂度$O(n \log n)$
注:$O(n \log n)$二分+单调栈才是真神仙
具体看代码
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; extern inline char gc() {
static char RR[], *S = RR + , *T = RR + ;
if(S == T) fread(RR, , , stdin), S = RR;
return *S ++;
}
inline int read() {
int p = , w = ; char c = gc();
while(c > '' || c < '') { if(c == '-') w = -; c = gc(); }
while(c >= '' && c <= '') p = p * + c - '', c = gc();
return p * w;
} #define mod 1000000007
#define ri register int
#define sid 50050 int n, cnp, H[sid], a[sid];
struct aha {
int len, num;
} t[sid], f[sid]; void upd(aha &x, aha y) {
if(x.len > y.len) return;
if(x.len < y.len) x = y;
else x.num += y.num, x.num %= mod;
} aha qry(int x) {
aha ret = { , };
for(ri i = x; i; i -= i &(-i)) upd(ret, t[i]);
return ret;
} aha add(int x, aha v) {
for(ri i = x; i <= cnp; i += i & (-i)) upd(t[i], v);
} int main() {
n = read();
for(ri i = ; i <= n; i ++) a[i] = H[i] = read();
sort(H + , H + n + );
cnp = unique(H + , H + n + ) - H - ;
for(ri i = ; i <= n; i ++) a[i] = lower_bound(H + , H + cnp + , a[i]) - H;
for(ri i = ; i <= n; i ++) {
f[i] = qry(a[i] - ); f[i].len ++;
add(a[i], f[i]);
}
aha ans = { , };
for(ri i = ; i <= n; i ++) upd(ans, f[i]);
printf("%d\n", ans.num);
return ;
}
51nod1376 最长上升子序列的数量的更多相关文章
- 51nod1376 最长递增子序列的数量
O(n2)显然超时.网上找的题解都是用奇怪的姿势写看不懂TAT.然后自己YY.要求a[i]之前最大的是多少且最大的有多少个.那么线段树维护两个值,一个是当前区间的最大值一个是当前区间最大值的数量那么我 ...
- 【51nod】1376 最长递增子序列的数量
数组A包含N个整数(可能包含相同的值).设S为A的子序列且S中的元素是递增的,则S为A的递增子序列.如果S的长度是所有递增子序列中最长的,则称S为A的最长递增子序列(LIS).A的LIS可能有很多个. ...
- 51NOD 1376 最长递增子序列的数量 [CDQ分治]
1376 最长递增子序列的数量 首先可以用线段树优化$DP$做,转移时取$0...a[i]$的最大$f$值 但我要练习$CDQ$ $LIS$是二维偏序问题,偏序关系是$i<j,\ a_i< ...
- 51nod 1376 最长递增子序列的数量(线段树)
51nod 1376 最长递增子序列的数量 数组A包含N个整数(可能包含相同的值).设S为A的子序列且S中的元素是递增的,则S为A的递增子序列.如果S的长度是所有递增子序列中最长的,则称S为A的最长递 ...
- 51nod 1376 最长上升子序列的数量 | DP | vector怒刷存在感!
51nod 1376 最长上升子序列的数量 题解 我们设lis[i]为以位置i结尾的最长上升子序列长度,dp[i]为以位置i结尾的最长上升子序列数量. 显然,dp[i]要从前面的一些位置(设为位置j) ...
- 51Nod 1376 最长递增子序列的数量 —— LIS、线段树
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1376 1376 最长递增子序列的数量 基准时间限制:1 秒 空 ...
- 51Nod 1376 最长递增子序列的数量 (DP+BIT)
题意:略. 析:dp[i] 表示以第 i 个数结尾的LIS的长度和数量,状态方程很好转移,先说长度 dp[i] = max { dp[j] + 1 | a[i] > a[j] && ...
- 673. Number of Longest Increasing Subsequence最长递增子序列的数量
[抄题]: Given an unsorted array of integers, find the number of longest increasing subsequence. Exampl ...
- 51nod 1376 最长递增子序列的数量(不是dp哦,线段树 + 思维)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1376 题解:显然这题暴力的方法很容易想到就是以每个数为结尾最 ...
随机推荐
- NYOJ 163 Phone List (字符串处理 字典树)
题目链接 描述 Given a list of phone numbers, determine if it is consistent in the sense that no number is ...
- 设计模式之Composite
设计模式总共有23种模式这仅仅是为了一个目的:解耦+解耦+解耦...(高内聚低耦合满足开闭原则) Composite定义? 将对象以树形结构组织起来,以达成“部分-整体” 的层次结构. 想到Compo ...
- 爬行百度标题&URL案例
思路: 先将需要获取的匹配出,然后可以用"永真"(即while True:)来遍历使得URL可以一直自增变化(百度点击下一页URL的pn参数就增加10)每增加10就爬行一遍URL然 ...
- 使用linux下的C操作SQLLITE
from: http://baike.so.com/doc/1529694.html 由于Linux下侧重使用命令,没有win的操作容易上手,所以在测试C操作SQLITE时会比较容易出现错误,给大家做 ...
- MySQL创建相同表和数据命令
创建和表departments结构和数据一样的表departments_t mysql> create table departments_t like departments; Query O ...
- Netty并发优化之ExecutionHandler
上文<Netty框架入门>说到:如果业务处理handler耗时长,将严重影响可支持的并发数. 针对这一问题,经过学习,发现了可以使用ExecutionHandler来优化. 先来回顾一下没 ...
- jQuery常用事件方法详解
目录 jQuery事件 ready(fn)|$(function(){}) jQuery.on() jQuery.click jQuery.data() jQuery.submit() jQuery事 ...
- chm转换为html文件
在Windows下chm转换为html的超简单方法(反编译CHM文件的方法) 通过调用Windows命令,将chm 文件转换为html 文件. 方法: 命令行(cmd),输入hh -decompile ...
- ISSCC 2017论文导读 Session 14 Deep Learning Processors,A 2.9TOPS/W Deep Convolutional Neural Network
最近ISSCC2017大会刚刚举行,看了关于Deep Learning处理器的Session 14,有一些不错的东西,在这里记录一下. A 2.9TOPS/W Deep Convolutional N ...
- hdu 4726(贪心)
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...