hdu2227---Find the nondecreasing subsequences(dp+树状数组)
来源:互联网 发布:网页淘宝分享到微信 编辑:程序博客网 时间:2024/05/23 19:17
Problem Description
How many nondecreasing subsequences can you find in the sequence S = {s1, s2, s3, …., sn} ? For example, we assume that S = {1, 2, 3}, and you can find seven nondecreasing subsequences, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}.
Input
The input consists of multiple test cases. Each case begins with a line containing a positive integer n that is the length of the sequence S, the next line contains n integers {s1, s2, s3, …., sn}, 1 <= n <= 100000, 0 <= si <= 2^31.
Output
For each test case, output one line containing the number of nondecreasing subsequences you can find from the sequence S, the answer should % 1000000007.
Sample Input
3
1 2 3
Sample Output
7
Author
8600
Recommend
lcy | We have carefully selected several similar problems for you: 2642 2688 1541 3030 3015
n达10万,所以用树状数组来优化
/************************************************************************* > File Name: hdu2227.cpp > Author: ALex > Mail: zchao1995@gmail.com > Created Time: 2015年06月02日 星期二 18时33分24秒 ************************************************************************/#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <bitset>#include <set>#include <vector>using namespace std;const double pi = acos(-1.0);const int inf = 0x3f3f3f3f;const double eps = 1e-15;typedef long long LL;typedef pair <int, int> PLL;static const int N = 100010;static const int mod = 1000000007;LL tree[N];int lowbit(int x) { return x & (-x);}void add(int n, int x, LL val) { for (int i = x; i <= n; i += lowbit(i)) { tree[i] += val; tree[i] %= mod; }}LL sum(int x) { LL ans = 0; for (int i = x; i; i -= lowbit(i)) { ans += tree[i]; ans %= mod; } return ans;}LL dp[N];int Arr[N];int xis[N];int cnt;int search(int val) { int l = 1, r = cnt; int mid; while (l <= r) { mid = (l + r) >> 1; if (xis[mid] == val) { break; } if (xis[mid] > val) { r = mid - 1; } else { l = mid + 1; } } return mid;}int main() { int n; while (~scanf("%d", &n)) { cnt = 0; memset(tree, 0, sizeof(tree)); for (int i = 1; i <= n; ++i) { scanf("%d", &Arr[i]); xis[++cnt] = Arr[i]; } sort(xis + 1, xis + cnt + 1); cnt = unique(xis + 1, xis + cnt + 1) - xis - 1; memset(dp, 0, sizeof(dp)); LL ans = 0; for (int i = 1; i <= n; ++i) { int val = search(Arr[i]); LL Sum = sum(val); dp[i] = 1 + Sum; dp[i] %= mod; add(n, val, dp[i]); ans += dp[i]; ans %= mod; } printf("%lld\n", ans); } return 0;}
- hdu2227---Find the nondecreasing subsequences(dp+树状数组)
- 树状数组 hdu2227 Find the nondecreasing subsequences
- HDU2227 Find the nondecreasing subsequences(树状数组+DP+离散化)
- hdu2227 Find the nondecreasing subsequences(dp+线段树or树状数组优化)
- HDU2227:Find the nondecreasing subsequences
- HDU2227 - Find the nondecreasing subsequences(线段树优化DP)
- hdu 2227 Find the nondecreasing subsequences 树状数组+简单DP
- hdoj 2227 Find the nondecreasing subsequences 【树状数组优化dp】
- hdu 2227 Find the nondecreasing subsequences(树状数组+DP)
- HDU2227(Find the nondecreasing subsequences)
- Find the nondecreasing subsequences--(树状数组)
- hdu 2227 Find the nondecreasing subsequences【离散化+树状数组+DP思路】
- hdu 2227 Find the nondecreasing subsequences (树状数组+dp+离散化)
- hdu 2227Find the nondecreasing subsequences(树状数组+dp+离散化)
- HDOJ 题目2227 Find the nondecreasing subsequences(树状数组,离散化,DP)
- hdu-2227-Find the nondecreasing subsequences(DP+离散化+树状数组)
- hdu 2227 Find the nondecreasing subsequences(树状数组)
- HDU 2227 Find the nondecreasing subsequences 树状数组
- 旋转数组的最小数字
- android设置全屏后无法启动activity的解决办法
- 为什么使用C++
- Oracle基础(no.1)
- 3-5
- hdu2227---Find the nondecreasing subsequences(dp+树状数组)
- java学习编程练习(局域网多人聊天功能的实现)
- OGG "Loading data from file to Replicat"table数据的静态同步配置过程
- Oracle基础(no.2)
- live555-让你的h264文件支持seek
- viewpage嵌套listview, 效果:滑动listview删除,滑动非listview区域viewpage翻页
- 7zip 压缩文件 分析
- c++第三次作业
- c++第四次作业