http://acm.hdu.edu.cn/showproblem.php?pid=2227

用dp[i]表示以第i个数为结尾的nondecreasing串有多少个。

那么对于每个a[i]

要去找 <= a[i]的数字那些位置,加上他们的dp值即可。

可以用树状数组维护

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int MOD = ;
const int maxn = + ;
LL a[maxn], b[maxn];
int n;
LL c[maxn];
LL lowbit(LL x) {
return x & (-x);
}
void UpDate(int pos, LL val) {
while (pos <= n) {
c[pos] += val;
if (c[pos] >= MOD) c[pos] %= MOD;
pos += lowbit(pos);
}
}
LL query(int pos) {
LL ans = ;
assert(pos >= );
while (pos) {
ans += c[pos];
pos -= lowbit(pos);
}
return ans;
}
void work() {
memset(c, , sizeof c);
for (int i = ; i <= n; ++i) {
cin >> a[i];
b[i] = a[i];
}
sort(b + , b + + n);
LL ans = ;
for (int i = ; i <= n; ++i) {
int pos = lower_bound(b + , b + + n, a[i]) - b;
LL tans = query(pos) + ;
ans += tans;
if (ans >= MOD) ans %= MOD;
UpDate(pos, tans);
}
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
IOS;
while (cin >> n) work();
return ;
}

HDU 2227 Find the nondecreasing subsequences dp思想 + 树状数组的更多相关文章

  1. HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences             ...

  2. HDU 2227 Find the nondecreasing subsequences(DP)

    Problem Description How many nondecreasing subsequences can you find in the sequence S = {s1, s2, s3 ...

  3. HDU 2227 Find the nondecreasing subsequences (线段树)

    Find the nondecreasing subsequences Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/3 ...

  4. 【CF314C】Sereja and Subsequences(DP,树状数组)

    题意:给定一个N个数的数列,求所有不同不下降子序列的乘积之和,其中不同指的是组成它的数字和长度不完全相同 n (1 ≤ n ≤ 10^5) a[i]<=10^6 思路:考虑DP.设DP[a[i] ...

  5. hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  6. HDU 3887:Counting Offspring(DFS序+树状数组)

    http://acm.hdu.edu.cn/showproblem.php?pid=3887 题意:给出一个有根树,问对于每一个节点它的子树中有多少个节点的值是小于它的. 思路:这题和那道苹果树是一样 ...

  7. uestc oj 1217 The Battle of Chibi (dp + 离散化 + 树状数组)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 给你一个长为n的数组,问你有多少个长度严格为m的上升子序列. dp[i][j]表示以a[i]结尾长为j ...

  8. HDU 5654 xiaoxin and his watermelon candy 离线树状数组 区间不同数的个数

    xiaoxin and his watermelon candy 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5654 Description Du ...

  9. HDU - 5542 The Battle of Chibi(LIS+树状数组优化)

    The Battle of Chibi Cao Cao made up a big army and was going to invade the whole South China. Yu Zho ...

随机推荐

  1. FZUOJ Problem 2200 cleaning DP

    Problem 2200 cleaning  Problem Description N个人围成一圈在讨论大扫除的事情,需要选出K个人.但是每个人与他距离为2的人存在矛盾,所以这K个人中任意两个人的距 ...

  2. ArchLinux最小化安装 必备库 常用命令

    铸成强大的工作站环境——ArchLinux最小化安装 所有问题归结起来,只是一个问题:ArchLinux最小化安装,需要安装哪些包? 1.bash//最基本的Bash Shell(必须)2.bzip2 ...

  3. 搭建双系统后没有windows的引导程序

    因为安装linux系统前没有安装引导程序,导致安装了linux系统后进入linux系统没有windows的引导程序,网上找了很多解决办法,也不能说是不好使,只是作为新手小白来说有点难以理解,最后无意中 ...

  4. SWT.Shell

    import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class SWT_Shell ...

  5. redis10---Setbit 的实际应用

    Setbit 的实际应用 场景: 1亿个用户, 每个用户 登陆/做任意操作 ,记为 今天活跃,否则记为不活跃 每周评出: 有奖活跃用户: 连续7天活动,每月评,等等. 思路: Userid dt ac ...

  6. 微信的API都是通过https调用实现的,分为post方法调用和get方法调用。不需要上传数据的采用get方法(使用IntraWeb开发)

    首先需要明确的是,微信的API都是通过https调用实现的,分为post方法调用和get方法调用.不需要上传数据的采用get方法(例如获取AccessToken),而需要向微信服务器提交数据的采用po ...

  7. Elasticsearch分布式安装启动失败

    配置config目录下的 elasticsearch.yml  http.cors.enabled: true http.cors.allow-origin: "*" #分布安装. ...

  8. 如何使用BMap.Point传递变量、存储数据?

    在开发中使用到了百度地图进行开发,用于展示企业位置.由于数据量庞大,如果使用marker,将会造成界面卡顿,处理慢的问题. 在查看百度地图API示例是发现了海量点这个东西,还别说对于大数量的点加载起来 ...

  9. 汇编环境的搭建(windows 10 + debug)

    1. debug.exe 安装 win10 版本过高,不再提供 debug.exe,甚至从别处获取的 debug.exe 的也无法运行. 汇编语言学习所需的各种执行文件(debug.exe.link. ...

  10. python(二):使用multiprocessing中的常见问题

    简介在python的解释器中,CPython是应用范围最广的一种,其具有丰富的扩展包,方便了开发者的使用.当然CPython也不是完美的,由于全局解释锁(GIL)的存在,python的多线程可以近似看 ...