题目

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. RabbitMQ之php-amqplib使用

    PHP下使用rabbitmq可以使用第三方类库来实现 技术参考: https://rabbitmq.shujuwajue.com/tutorials_with_php/[1]Hello_World.h ...

  2. antd form 自定义验证表单使用方法

    import React from 'react'; import classNames from 'classnames'; export default class FormClass exten ...

  3. 运行错误:Application Error - The connection to the server was unsuccessful

    在模拟器上上启动ionic4.6版本 打包成的android APK,启动了很久结果弹出这个问题: Application Error - The connection to the server w ...

  4. DAY21、面向对象

    一.内存管理与正则语法1.内存管理:引用计数:垃圾回收机制工作原理 引用就 +1 ,释放就 -1 ,当计数为0时,就会被垃圾回收机制回收标记清除:解决循环导入引用导致的内存泄漏 标记:GC roots ...

  5. bugku crypto 告诉你一个秘密(ISCCCTF)

    emmmm....有点坑 题目: 636A56355279427363446C4A49454A7154534230526D6843 56445A31614342354E326C4B4946467A57 ...

  6. Spring Boot 2.x 编写 RESTful API (四) 使用 Mybatis

    用Spring Boot编写RESTful API 学习笔记 添加依赖 <dependency> <groupId>org.mybatis.spring.boot</gr ...

  7. 网站PWA升级

    前面的话 渐进式网络应用 ( Progressive Web Apps ),即我们所熟知的 PWA,是 Google 提出的用前沿的 Web 技术为网页提供 App 般使用体验的一系列方案.PWA 本 ...

  8. [SHOI2007]善意的投票

    题目描述 幼儿园里有n个小朋友打算通过投票来决定睡不睡午觉.对他们来说,这个问题并不是很重要,于是他们决定发扬谦让精神.虽然每个人都有自己的主见,但是为了照顾一下自己朋友的想法,他们也可以投和自己本来 ...

  9. 20165223 《信息安全系统设计基础》 stat命令的实现-mysate

    学习使用stat(1),并用C语言实现                1. 提交学习 stat(1) 的截图                2. man -k ,grep -r的使用          ...

  10. js-sha256源码

    /** * [js-sha256]{@link https://github.com/emn178/js-sha256} * * @version 0.9.0 * @author Chen, Yi-C ...