【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长度 + 以它 ...
随机推荐
- php curl向远程服务器上传文件
<?php /** * test.php: */ header('content-type:text/html;charset=utf8'); $ch = curl_init(); //加@符号 ...
- Python升级Yum不能使用解决
1.系统版本 [root@vm10-254-206-95 ~]# cat /etc/issue CentOS release 6.4 (Final) Kernel \r on an \m 2.系统默认 ...
- set_include_path — 设置 include_path 配置选项为当前脚本设置 include_path 运行时的配置选项。
说明 string set_include_path ( string $new_include_path ) 为当前脚本设置 include_path 运行时的配置选项. 参数 new_includ ...
- postgresql 热备与恢复
一. PostgreSQL热备份的过程一般为: 数据库中执行:pg_start_backup() ; 然后使用操作系统的tar或 cp命令拷贝 PostgreSQL数据文件. 数据库中执行:pg_st ...
- hdwiki中模板的使用说明
HDwiki所有模版文件都在根目录view下的default文件里,以admin_开头的是后台的模版文件,其它不是以admin_开头的,就是所有的前台文件.具体列表如下:首页模版文件: index. ...
- 关于left join、right join和inner join
总结, 1.select * from A left join B on A.XX=B.XX 左侧显示A的列名,右侧显示B的列名 左侧,显示A表的所有列 右侧, A.XX=B.XX的时候,显示B表的列 ...
- ScheduledExecutorService定时周期执行指定的任务
示例代码 package com.effective.common.concurrent.execute; import java.text.DateFormat; import java.text. ...
- sql 取时间 问题集
一. AND B.TRAFFICE_DATE>dateadd(day,5,(select getdate())) dateadd(day,5,(select getdate())):为当前时间+ ...
- 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...
- 循环嵌套,while循环,穷举迭代循环
一.循环嵌套 简单的就是说,在一个for循环里嵌入多个小for循环. 其中,在打矩形.三角形和乘法口诀表之类的题目中,大for循环一般表示的是行数,其余的小for循环式每一行中的内容. 二.while ...