hdu2227---Find the nondecreasing subsequences(dp+樹狀數組)
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
dp[i]表示以第i個元素結尾的不下降序列個數
dp[i]=∑i?1j=1 dp[j] +1
n達10萬,所以用樹狀數組來優化
/*************************************************************************
> File Name: hdu2227.cpp
> Author: ALex
> Mail: [email protected]
> Created Time: 2015年06月02日 星期二 18時33分24秒
************************************************************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include