和之前的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. How to Change MAC Address on Ubuntu

    1 Open Terminal.   2 Log in as root so type: sudo -i and then write your password.   3 View your cur ...

  2. rm命令删除文件时排除特定文件

    删除文件时排除特定文件 www.python  tab.com/html/2013/linuxkaiyuan_0205/214.html 删除当前目录下所有 *.txt文件,除了test.txt 1 ...

  3. 工具类Utils的单元测试方式

    数据质量功能已经开发完毕,但是要实现单元测试覆盖率80%以上,其他的还好,只是这个工具类实在让我摸不着头脑,其实工具类的单元测试是最简单的,只是自己想复杂了而已: 无返回值模拟: 有返回值模拟: 异常 ...

  4. HTTP协议是什么

    1.http全称Hypertext Trsnsfer Protocol超文本传输协议 2.最初发明是用来在浏览器和web服务器之间传输超文本信息的 3.泛义上属于应用层的协议   ,很多其他应用(比如 ...

  5. Spring整合jedis 集群模式

    引入jedis依赖 <dependency> <groupId>redis.clients</groupId> <artifactId>jedis< ...

  6. ViewPager源码分析——滑动切换页面处理过程

    上周客户反馈Contacts快速滑动界面切换tab有明显卡顿,让优化. 自己验证又没发现卡顿现象,但总得给客户一个技术性的回复,于是看了一下ViewPager源码中处理滑动切换tab的过程. View ...

  7. Android Makefile中是 如何识别 TARGET_PRODUCT 的

    http://blog.csdn.net/stevenliyong/article/details/5285334 今天有时间小看一下Android 的Makefile, 终于稍有明白Android ...

  8. 关于Code Review

    为了保证代码质量,我们团队内部一直在推行Code Review.现在Code Review帮我们发现了很多代码的问题,提升了代码的可读性和质量,同时我们在Code Review上也花费了很多时间,有些 ...

  9. Java往hbase写数据

    接上篇读HDFS 上面读完了HDFS,当然还有写了. 先上代码: WriteHBase public class WriteHBase { public static void writeHbase( ...

  10. 安装了nodejs后在命令行运行npm报错:Error: Cannot find module 'internal/util/types'

    报错如下图所示: 解决方法:删除目录“C:\Users\wls\AppData\Roaming\npm\node_modules”下的npm文件夹