和之前的hdu3030都快一样了

可以参考之前的题解

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e5+;
long long n;
long long a[maxn];
long long b[maxn];
long long c[maxn];
long long mod = 1e9+;
void add(long long c[],long long i,long long j);
long long getsum(long long c[],long long i);
int main()
{
int i,j,k;
while(scanf("%lld",&n) != EOF)
{
memset(c, , sizeof(c));
for(i=;i<=n;++i)
{
scanf("%lld",a+i);
b[i] = a[i];
}
sort(b+,b+n+);
long long sum = ;
for(i=;i<=n;++i)
{
long long ans=;
long long pos=lower_bound(b+,b+n+,a[i]) - b;
ans = getsum(c,pos);
sum += ans+;
sum %= mod;
add(c, pos, ans+);
}
printf("%lld\n",sum);
}
}
long long lowbit(long long k)
{
return k&(-k);
}
void add(long long c[],long long i,long long j)
{
while(i<=n)
{
c[i] += j;
c[i] %= mod;
i += lowbit(i);
}
}
long long getsum(long long c[],long long i)
{
long long sum = ;
while(i > )
{
sum += c[i];
sum %= mod;
i -= lowbit(i);
}
return sum;
}

hdu 2227的更多相关文章

  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思想 + 树状数组

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

  3. HDU 2227 Find the nondecreasing subsequences

    题目大意:给定一个序列,求出其所有的上升子序列. 题解:一开始我以为是动态规划,后来发现离散后树状数组很好做,首先,c保存的是第i位上升子系列有几个,那么树状数组的sum就直接是现在的答案了,不过更新 ...

  4. HDU 2227 Find the nondecreasing subsequences (线段树)

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

  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 Find the nondecreasing subsequences (数状数组)

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

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

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

  8. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  9. BIT 树状数组 详解 及 例题

    (一)树状数组的概念 如果给定一个数组,要你求里面所有数的和,一般都会想到累加.但是当那个数组很大的时候,累加就显得太耗时了,时间复杂度为O(n),并且采用累加的方法还有一个局限,那就是,当修改掉数组 ...

随机推荐

  1. window 安装gdal和python

    进入 http://www.gisinternals.com/release.php 中下载下图(也可以不是这个版本但是下载的python和gdal一定要版本对应) 1.点击下图中release-17 ...

  2. ubuntu如何实现双屏显示

    转载自https://blog.csdn.net/tianmaxingkong_/article/details/50570538

  3. java指针与引用(转载)

    大家都知道java和C#中没有指针这个概念.但是也导致了编程中常常忽略了对象与引用的区别,难道java真的没有指针吗?句柄是什么?变量地址在哪里?没有地址是不可能的,关键是java中如何避免了指针这个 ...

  4. android模拟器不能上网设置

    进行sdk目录中的platform-tools目录: adb devices 系统会罗列出所有设置 adb -s emulator- shell 最后设置网关 setprop net.dns1 192 ...

  5. android DatagramSocket send 发送数据出错

    安卓4.0以后好像不能在主线程里面使用 socket 所以不管是发送数据还是接收数据需要新开一个了线程: 以下代码是我点击发送是代码: new Thread(new Runnable() { @Ove ...

  6. spring学习七 spring和dynamic project进行整合

    spring和web项目进行整合,其实就是在项目启动时,就创建spring容器,然后在servlet中使用spring容器进行开. 注意:为了页面可以访问到servlet,因此servlet必须放进t ...

  7. windows下tomcat+nginx+openssl配置双向认证

    1. 基础知识 CA证书:https://blog.csdn.net/yangyuge1987/article/details/79209473 SSL双向认证原理:https://blog.csdn ...

  8. 再读c++primer plus 002

    1.读取char值时,与读取其它基本类型一样,cin将忽略空格和换行符,函数cin.get(ch)读取输入的下一个字符(即使是空格),并将其赋给变量ch. 2.指针和const:(1)让指针指向一个常 ...

  9. docker 加速器配置目录

    centos 7 : /lib/systemd/system/docker.service

  10. 2018.11.03 NOIP模拟 地球发动机(线性dp)

    传送门 考试5分钟写完. 如果没这题今天多半爆零了(汗 直接二分出合法的转移范围. 然后用后面的状态更新前面的就可以了. 代码