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 ...
随机推荐
- linux查看目录下各个文件大小的命令
linux查看目录下各个文件大小的命令 由于需要经常查看各个文件的具体大小 ,所以这里记一下. 命令如下: du -h --max-depth=1
- gitlab搭建和使用
原文地址:https://blog.csdn.net/zhushuai662/article/details/79581377 大家常听说Git.Github.Gitlab,很多人对着三个词很懵逼,分 ...
- 关系型数据库 VS 非关系型数据库
一.关系型数据库? 1.概念 关系型数据库是指采用了关系模型来组织数据的数据库.简单来说,关系模式就是二维表格模型. 主要代表:SQL Server,Oracle,Mysql,PostgreSQL. ...
- 调试ucosii_pendsv中断函数有感
发现自己的代码的意思和自己理解的意思有不相同的时候,自己先用printf打印输出分析 当发现是自己那一个知识点没有掌握好时,自己用其他的C编译器,仿写用到的知识点的程序,然后掌握该知识点. 最后实在找 ...
- pjb fabu
#!/bin/bash PyPath=/opt/shell/mysql LocaName=`pwd` bagname=`basename $LocaName` sleep 1s ConfList=`p ...
- P3414 SAC#1 - 组合数 题解
https://www.luogu.org/problemnew/show/P3414(题目传送) 这道题提醒大家一定要认真审题.看清楚后发现n的数据范围稍微小于long long类型的范围(看不清被 ...
- linux 单用户密码修改
1.启动系统,并在GRUB2启动屏显时,按下e键进入编辑模式. 2.在linux16/inux/linuxef所在参数行ro更改为init=/sysroot/bin/sh 3.按Crl+x启动到she ...
- MySQL8.0.19主从环境搭建(CentOS7)
默认情况下,复制是异步的,从站不需要永久连接以接收来自主站的更新.根据配置,您可以复制数据库中的所有数据库,所选数据库甚至选定的表. MySQL中复制的优点包括: 横向扩展解决方案 - 在多个从站之间 ...
- Arrays和String单元测试(课下作业,选做)
在IDEA中以TDD的方式对String类和Arrays类进行学习- 测试相关方法的正常,错误和边界情况 - String类 - charAt - split - Arrays类 - sort - b ...
- easyui Datagrid 表格高度计算及自适应页面的实现
因为页面上既要计算表格的高度,又要自适应浏览器大小,之前都都采用固定表格高度,这样就会导致不同的分辨率电脑上看起来表格高矮不一, 所以采用了计算网页高度和其他div 的高度之差作为表格的初始高度: H ...