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. 《写给大忙人看的java》笔记--基本的编程结构

    1.字符串是UTF-16编码中的Unicode编码点的序列 2.绑定System.in的Scanner可以读取终端输入: Scanner sc = new Scanner(System.in); 3. ...

  2. Xamarin.Android 记事本(一)

    导读 1.视图及数据库的创建 2.listview数据绑定 3.listview的点击事件 正文 如何创建一个listview,大家可以看这里,基本流程操作是一模一样的,我就不多说了,然后就是新建一个 ...

  3. Docker and Go: why did we decide to write Docker in Go?

    Docker and Go: why did we decide to write Docker in Go? | Hacker News https://news.ycombinator.com/i ...

  4. 开启 J2EE(六)— Servlet之Filter具体解释及乱码处理实例

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/akkzhjj/article/details/36471477 定义和功能 Filter:过滤器,它 ...

  5. DeepLearningFlappyBird-深度学习玩游戏-1-环境搭建

    -------------------------------------------------------------------------------------- https://githu ...

  6. iOS 获取WIFI SSID及MAC地址

    NSString *ssid = @"Not Found"; NSString *macIp = @"Not Found"; CFArrayRef myArra ...

  7. (linux)SD卡初始化-mmc_sd_init_card函数(续)

      转自:http://www.cnblogs.com/fengeryi/p/3472728.html   mmc_sd_init_card剩下的关于UHS-I的分支结构. uhs-I的初始化流程图如 ...

  8. POJ3104 Drying —— 二分

    题目链接:http://poj.org/problem?id=3104 Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissio ...

  9. HDU 2036:改革春风吹满地

    改革春风吹满地 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  10. codeforces 669E E. Little Artem and Time Machine(节点为map型的线段树)

    题目链接: E. Little Artem and Time Machine time limit per test 2 seconds memory limit per test 256 megab ...