Find the nondecreasing subsequences

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2213    Accepted Submission(s): 858

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
     
    令f(i)表示以第i个元素为结尾的非递减子序列的个数,有 f(i)=SUM{f(j) | j<i&&a[j]<=a[i]}。
        用BIT来维护f,C[x]表示所有的f总和,下标反映的就是a[i]得值,这样在求解f(i)=sum(a[i])就好了。
    注意到ai范围较大,离散化处理一下。
 
  

 #include<bits/stdc++.h>
using namespace std;
#define ULL unsigned long long
#define LL long long
LL mod=1e9+;
LL C[];
int N;
struct node{
int v,d;
bool operator<(const node& C)const{
if(v!=C.v) return v<C.v;
return d<C.d;
}
}a[];
bool cmp(node A,node B){return A.d<B.d;}
int main(){
int i,j;
while(scanf("%d",&N)==){
LL ans=;
for(i=;i<=N;++i) scanf("%d",&a[i].v),a[i].d=i;
sort(a+,a++N);
for(i=;i<=N;++i) a[i].v=i;
sort(a+,a++N,cmp);
for(i=;i<=N;++i){
LL tmp=;
for(int x=a[i].v;x>;x-=(x&-x)) (tmp+=C[x])%=mod;
for(int x=a[i].v;x<=N;x+=(x&-x)) (C[x]+=tmp)%=mod;
(ans+=tmp)%=mod;
}
printf("%lld\n",ans);
memset(C,,sizeof(C));
}
return ;
}

hdu-2227-dp+bit的更多相关文章

  1. hdu 3016 dp+线段树

    Man Down Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  2. HDU 5928 DP 凸包graham

    给出点集,和不大于L长的绳子,问能包裹住的最多点数. 考虑每个点都作为左下角的起点跑一遍极角序求凸包,求的过程中用DP记录当前以j为当前末端为结束的的最小长度,其中一维作为背包的是凸包内侧点的数量.也 ...

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

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

  4. HDU 2227 Find the nondecreasing subsequences dp思想 + 树状数组

    http://acm.hdu.edu.cn/showproblem.php?pid=2227 用dp[i]表示以第i个数为结尾的nondecreasing串有多少个. 那么对于每个a[i] 要去找 & ...

  5. HDU 2227 Find the nondecreasing subsequences(DP)

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

  6. hdu 2227(树状数组+dp)

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

  7. HDU 1069 dp最长递增子序列

    B - Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  8. HDU 1160 DP最长子序列

    G - FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  9. hdu 4826(dp + 记忆化搜索)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4826 思路:dp[x][y][d]表示从方向到达点(x,y)所能得到的最大值,然后就是记忆化了. #i ...

  10. HDU 2861 (DP+打表)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2861 题目大意:n个位置,m个人,分成k段,统计分法.S(n)=∑nk=0CknFibonacci(k ...

随机推荐

  1. ELK学习笔记之Elasticsearch启动常见错误

    问题出现的环境: OS版本:CentOS-7-x86_64-Minimal-1708 ES版本:elasticsearch-6.2.2 1. max file descriptors [4096] f ...

  2. 获取Json字符串中的key和value

    获取Json字符串中的key和value 在web项目中经常会用到json数据(如:struts2处理请求返回json数据给jsp解析),因此,JSONObject对象是必备的,这时就需要引入相关的j ...

  3. expect交互式创建账号密码

    这个脚本是我在建立samba用户的时候用到的,一开始我是一步一步的操作,后来嫌麻烦了,就写了这个脚本,也学习了一下expect. #!/usr/bin/expectset user [lindex $ ...

  4. 20145331魏澍琛《网络对抗》Exp2 后门原理与实践

    20145331魏澍琛<网络对抗>Exp2 后门原理与实践 基础问题回答 (1)例举你能想到的一个后门进入到你系统中的可能方式? 上网时候弹出一个广告说你中奖了,或者你可以贷款10万元之类 ...

  5. P3709 大爷的字符串题

    题意 询问区间众数出现的次数 思路 唯有水题快人心 离散化+莫队 莫队一定要先加后减,有事会出错的 莫队维护区间众数: 维护两个数组,一个数组记录权值为x的出现次数,一个记录出现次数为x的数的个数 a ...

  6. 李白打酒|2014年蓝桥杯B组题解析第三题-fishers

    李白打酒 话说大诗人李白,一生好饮.幸好他从不开车. 一天,他提着酒壶,从家里出来,酒壶中有酒2斗.他边走边唱: 无事街上走,提壶去打酒. 逢店加一倍,遇花喝一斗. 这一路上,他一共遇到店5次,遇到花 ...

  7. POJ 3480 John(SJ定理博弈)题解

    题意:n堆石头,拿走最后一块的输 思路:SJ定理:先手必胜当且仅当:(1)游戏的SG函数不为0且游戏中某个单一游戏的SG函数大于1:(2)游戏的SG函数为0且游戏中没有单一游戏的SG函数大于1. 参考 ...

  8. Max Factor(素数筛法)题解

    Max Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. [luogu 3957]跳房子

    题目链接 50分做法 挺显然的一个做法,因为金币量是单调的(如果你花i枚金币可以得到最优解,i+1枚也一定可以),所以可以二分答案 然后对于二分出来的每个答案,都做一遍dp,效率$O(n^2logn) ...

  10. 【Django】【四】测试

    [Testing in Django] 通过参数可控制Django项目不同级别的测试. 1. 运行sign应用下所有的测试用例: \\guest\python manage.py test sign ...