题目

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的更多相关文章

  1. Light oj 1085 - All Possible Increasing Subsequences (简单dp + 离散化 + BIT)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1085 题意: 问你有多少个上升子序列. 思路: dp[i]表示以第i个数结尾的 ...

  2. LightOJ 1085 - All Possible Increasing Subsequences 树状数组+离散

    http://www.lightoj.com/volume_showproblem.php?problem=1085 题意:求一个序列的递增子序列个数. 思路:找规律可以发现,某个数作为末尾数的种类数 ...

  3. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  4. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  5. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  6. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

  7. [LeetCode] Increasing Subsequences 递增子序列

    Given an integer array, your task is to find all the different possible increasing subsequences of t ...

  8. [Swift]LeetCode491. 递增子序列 | Increasing Subsequences

    Given an integer array, your task is to find all the different possible increasing subsequences of t ...

  9. 491. Increasing Subsequences增长型序列

    [抄题]: Given an integer array, your task is to find all the different possible increasing subsequence ...

随机推荐

  1. 免费高端出辕营,横空出世惊鬼神 Excel插件:ExcelPower_Helper 0.41初出茅庐

    免费高端出辕营,横空出世惊鬼神 Excel插件:ExcelPower_Helper 0.41初出茅庐        隐鹤 倾心开发 2019.4.1 1.   引言 经过前后大约零零散散的一年的开发, ...

  2. 2019-04-28 Mybatis generator逆向工程生成的Example代码分析

    今天主要对Mybatis generator生成的DAO层等进行分析,讲解Example类的使用和扩展 1.先在数据库建表 CREATE TABLE `department` ( `fid` ) NO ...

  3. 转载泡泡机器人——IMU预积分总结与公式推导2

    本文为IMU预积分总结与公式推导系列技术报告的第二篇. 承接第一篇的内容,本篇将推导IMU预积分的测量值,并分析其测量误差的分布形式. 传统捷联惯性导航的递推算法,以初始状态为基础,利用IMU测量得到 ...

  4. 接口测试(jmeter和postman 接口使用)

    接口测试基础知识 接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点.把前端(client)和后端(server)联系起来,测试的重点是要检查数据的交换,传递和控制管理过程,以及系统 ...

  5. 「洛谷4197」「BZOJ3545」peak【线段树合并】

    题目链接 [洛谷] [BZOJ]没有权限号嘤嘤嘤.题号:3545 题解 窝不会克鲁斯卡尔重构树怎么办??? 可以离线乱搞. 我们将所有的操作全都存下来. 为了解决小于等于\(x\)的操作,那么我们按照 ...

  6. ubuntu18.04安装mysql

    ubuntu18.04中,默认情况下mysql默认包含在apt软件存储库中,要安装它只需要更新服务器上的包索引并安装默认包apt-get. 1.安装mysql sudo apt-get update ...

  7. Git如何合并一个已经在GitHub上提交但没有合并的Pull Request请求

    步骤 进入Git仓库,执行curl -L https://github.com/<USER>/<REPO>/pull/<NO>.patch | git am

  8. HAOI2019+十二省联考 游记

    Day1 T1 考前还奶了一口不会考01Trie的,也就没有学,然后60分BOOM T2 不会SAM,告辞,30分滚粗 T3 传统实现题答?2p,2u,2g分别对应素数,莫比乌斯函数,原根?没看出来, ...

  9. vue中的computed(计算属性)和watch(监听属性)的特点,以及深度监听

    //计算属性是根据data中已有的属性,计算得到一个新的属性, <div>全名:{{fullName}}</div> 创建计算属性通过computed关键字,它是一个对象 计算 ...

  10. C#调用Java的WebService添加SOAPHeader验证

    C#调用Java的WebService添加SOAPHeader验证(2) 1.问题描述 调用的Java的webservice string Invoke(string func, string req ...