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 题解:显然这题暴力的方法很容易想到就是以每个数为结尾最 ...
随机推荐
- laravel前台html代码不显示
后天向前台传输变量,如果能取到变量数据,还有代码,但是不显示图片 可以把{{}}换成{!! !!}试试.
- mybatis错误总结
1:传递多个参数失败 Parameter 'username' not found. Available parameters are [0, 1, param1, param2] dao层错误写 ...
- https://segmentfault.com/bookmark/1230000008276077
https://segmentfault.com/bookmark/1230000008276077
- Hibernate总结之常用API
1. Configuration Configuration是用来读取配置文件,从配置文件中构件SessionFactory的. SessionFactory sessionFactory=new C ...
- [转载]Android中Bitmap和Drawable
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...
- callee与caller
1.callee arguments.callee表示当前函数,使用于递归 function factorial(num){ if(num<=1){ return 1; }else{ retur ...
- redhat5.5 x64 安装oracle 11g
http://www.cnblogs.com/jamesf/p/4769086.html http://blog.csdn.net/yakson/article/details/9012129
- git常用命令速查表【转】
- python3.x的HTMLTestRunner.py文件
"""A TestRunner for use with the Python unit testing framework. Itgenerates a HTML re ...
- php判断是手机还是pc访问从而走不同url
<?php header("Content-type:text/html;charset=utf-8"); function is_mobile(){ $user_agent ...