HDU find the nondecreasing subsequences
来源:互联网 发布:手机渗透软件 编辑:程序博客网 时间:2024/06/07 03: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
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
ll n;
ll a[100005],b[100005];
ll c[100005],dp[100005];
struct Node
{
ll value;
int index;
bool operator < (const Node&b)const
{
return value<b.value;
}
}node[100005];
ll lowbit(ll i)
{
return i&(-i);
}
void updata(ll i,ll data)
{
while(i<=n)
{
c[i]+=data;
c[i]=c[i]%1000000007;
i+=lowbit(i);
}
}
ll query(ll i)
{
ll res=0;
while(i>0)
{
res+=c[i];
i-=lowbit(i);
}
return res%1000000007;
}
int main()
{
int i,j;
while(~scanf("%lld",&n))
{
memset(dp,0,sizeof(dp));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
for(i=1;i<=n;i++)
{
scanf("%lld",&node[i].value);
node[i].index=i;
}
sort(node+1,node+n+1);
b[ node[1].index ]=1;
for(i=2;i<=n;i++)
{
if(node[i].value==node[i-1].value)
b[ node[i].index ]=b[ node[i-1].index ];
else
b[ node[i].index ]=i;
}
for(i=1;i<=n;i++)
{
dp[i]=query(b[i]);
updata(b[i],dp[i]+1);
}
cout<<query(n)<<endl;
}
return 0;
}
- HDU find the nondecreasing subsequences
- hdu 2227 Find the nondecreasing subsequences
- Find the nondecreasing subsequences HDU 2227
- HDU 2227 Find the nondecreasing subsequences
- HDU - 2227 Find the nondecreasing subsequences
- HDU - 2227 Find the nondecreasing subsequences
- HDU 2227 Find the nondecreasing subsequences(DP)
- HDU 2227 Find the nondecreasing subsequences
- Find the nondecreasing subsequences
- HDU2227:Find the nondecreasing subsequences
- hdu 2227 Find the nondecreasing subsequences(树状数组)
- 线段树 HDU 2227 Find the nondecreasing subsequences
- HDU 2227 Find the nondecreasing subsequences 树状数组
- hdu 2227 Find the nondecreasing subsequences 树状数组+简单DP
- HDU 2227 Find the nondecreasing subsequences (线段树)
- hdu-Find the nondecreasing subsequences(树状数组)
- HDU--2227--Find the nondecreasing subsequences--线段树
- hdu 2227 Find the nondecreasing subsequences(树状数组+排序)
- 最少硬币
- Eclipse和STS中添加文档注释快捷键
- QQ空间自动点赞代码 网页版代码
- 利用JNI技术在Android中调用C、调试C++代码(工具,详解)
- Java 字节输入流的一些方法
- HDU find the nondecreasing subsequences
- JSP常用内置对象
- Struts2学习第五天:9种Result类型
- LeetCode Weekly Contest 46解题思路
- NOIP 算法小结
- 微分和导数的关系是什么?
- Activiti流程图实例
- for循环输出空心菱形的形状【java】
- hpu 【1190】確率(组合数学)