Light OJ 1085 - All Possible Increasing Subsequences
题目
link
给定一个序列, 求出上升子序列的总数。
分析
Dp[i] 表示序列 以 i 结尾的数目。
可知 Dp[i]=∑Dp[x]+1
这是一个前缀和, 用树状数组维护。
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 131;
const LL MOD = 1e9 + 7;
LL Num[maxn], A[maxn], B[maxn];
int n;
int lowebit(int x) { return x&(-x); }
LL Sum(int x) {
LL ret = 0;
while(x > 0)
{
ret = (ret + Num[x]) % MOD;
x -= lowebit(x);
}
return ret;
}
void Update(int x, LL Val) {
while(x <= n)
{
Num[x] = (Num[x] + Val) % MOD;
x += lowebit(x);
}
}
int main()
{
int t;
scanf("%d",&t);
for(int kase = 1; kase <= t; ++kase)
{
scanf("%d",&n);
memset(Num, 0, sizeof(Num));
for(int i = 0; i < n; ++i)
scanf("%lld",A+i), B[i] = A[i];
sort(A, A+n);
int Max = unique(A, A+n)-A;
for(int i = 0; i < n; ++i)
{
B[i] = lower_bound(A, A+Max, B[i])-A + 1;
}
//cout << "1" <<endl;
for(int i = 0; i < n; ++i)
{
LL s = Sum(B[i]-1) + 1;
//cout << "2" << " " <<B[i] <<endl;
s %= MOD;
Update(B[i], s);
//cout << "3" <<endl;
}
LL Ans = Sum(n);
printf("Case %d: %lld\n",kase, Ans);
}
return 0;
}
Light OJ 1085 - All Possible Increasing Subsequences的更多相关文章
- Light oj 1085 - All Possible Increasing Subsequences (简单dp + 离散化 + BIT)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1085 题意: 问你有多少个上升子序列. 思路: dp[i]表示以第i个数结尾的 ...
- LightOJ 1085 - All Possible Increasing Subsequences 树状数组+离散
http://www.lightoj.com/volume_showproblem.php?problem=1085 题意:求一个序列的递增子序列个数. 思路:找规律可以发现,某个数作为末尾数的种类数 ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
- [LeetCode] Increasing Subsequences 递增子序列
Given an integer array, your task is to find all the different possible increasing subsequences of t ...
- [Swift]LeetCode491. 递增子序列 | Increasing Subsequences
Given an integer array, your task is to find all the different possible increasing subsequences of t ...
- 491. Increasing Subsequences增长型序列
[抄题]: Given an integer array, your task is to find all the different possible increasing subsequence ...
随机推荐
- Ubuntu本地文件上传至HDFS文件系统出现的乱码问题及解决方案
1.问题来源及原因 用shell命令上传到HDFS中之后出现中文乱码,在shell命令窗口查看如图: 在eclipse中的文件HDFS查看工具查看如图: 原因:上传至HDFS文件系统的文本文件(这里是 ...
- html5+ 原生标题栏添加input 输入框
titleNView: { backgroundColor: "#f7f7f7", // 导航栏背景色 titleText: "", // 导航栏标题 titl ...
- DAY30、网络编程
一.网络编程 软件开发 c/s架构 c:客户端 s:服务端 b/s架构 b:浏览器 s:服务端 本质:b/s其实也是c/s 服务端:24小时不间断提供服务,谁来救服务谁 客户端:想什么时候体验服务,就 ...
- day02-运算符 and 和 or 的用法
# 运算符的优先级 # () > not > and > or # and 必须两边表达式都为真,才为真 # or 如果表达式有一边为真,则为真 # not 表示非.比如 not 2 ...
- LOJ2083 [NOI2016] 优秀的拆分 【哈希】【调和级数】
题目分析: 好题!我们发现题目实际是要求出从某个左端点开始跑出去的BB型有多少个和从某个右端点开始跑出去的AA型有多少个. 发现这个问题是对称的,所以只考虑从左端点跑出去的BB型有多少个就可以了. 我 ...
- OrCAD原理图中怎么导出FPGA的引脚分配
流程 (1)选择tool下的export FPGA: (2)选择厂商,选择器件型号.选择生成文件类型. 以上.
- String方法,js中Array方法,ES5新增Array方法,以及jQuery中Array方法
相关阅读:https://blog.csdn.net/u013185654/article/details/78498393 相关阅读:https://www.cnblogs.com/huangyin ...
- winform动态生成新窗体并添加控件执行命令
主要代码 Form nf = new Form(); ; ; nf.Width = _w; nf.Height = _h; //添加textbox TextBox tb = new TextBox() ...
- 01Design and Analysis Algorithm Using Python-程振波
1.(p14)比较两个数的大小 a = int(input('num:')) b = int(input('num:')) def getMax(a,b): if a>b : print('Th ...
- python_unittest学习小结