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 ...
随机推荐
- C++ WMI获取系统硬件信息(CPU/DISK/NetWork etc)
官网找到一个例子,根据例子修改下可以获取很多信息 #define _WIN32_DCOM #include <iostream> using namespace std; #include ...
- consumer zookeeper is not a recognized option
kafka 创建消费者报错 consumer zookeeper is not a recognized option 在做kafka测试的时候,使用命令bin/kafka-console-consu ...
- js判断iPhone XS、iPhone XS Max、iPhone XR
// iPhone X.iPhone XS && window.screen.width === && window.screen.height === ; // iP ...
- React Native & iframe & WebView
React Native & iframe & WebView React Native 怎么渲染 iframe 页面 WebView & source html https: ...
- android 调用 screenrecord 实现录屏
首先要说明的是并未实现,本文讲一下自己的思路. adb 使用shell 命令 screenrecord 可录屏. 自己写了个app,通过Process p = Runtime.getRuntime() ...
- jmeter+maven+jenkins自动化接口测试(下)
maven+jmeter已经写好了,可以通过maven来执行jmeter的接口测试脚本,怎样实现定时执行测试并发送报告邮件就需要通过jenkins了(jmeter或者testng也可以结合不同的邮件j ...
- 运行selenium脚本,报seleneium common exception.SessionNotCreatedException:Message:Unable to find a matching set of capabilities错误
- java基础-容器-Set
Set:set不存重复元素,如果是使用set存储java预定义的Integer,String等类型会很简单,如果是存储自定义类型的数据类型,就必须要重新定义equals()方法以确保set中保存的对象 ...
- 【JS】使用变量作为object的key-方法汇总
1.方法一 var a = 'id'; var str = '{'+a+' : 12}' var obj = eval("("+str+")"); 结果: ob ...
- Apicloud学习第三天——获取云数据库的数据方法
apicloud学习30天中的对用进行注册和登录以及数据的获取的代码,在apicloud中有单独的api对用户的增删查改进行操作,这里写下增加和查询. 增加用户数据 var model=api.req ...