题目大意:给定一个序列,求出其所有的上升子序列。

题解:一开始我以为是动态规划,后来发现离散后树状数组很好做,首先,c保存的是第i位上升子系列有几个,那么树状数组的sum就直接是现在的答案了,不过更新时不要忘记加1,因为当前元素本身也是一个子序列,比如数列离散后为1 3 2 4 5,那么第一位得到之前的答案为0,更新时1位加1,第二位算出为1,更新时3位加(1+1),第三位也一样,一次类推,同树状数组求逆序对的方法一样,但是更新的不是1,而是之前所有的答案数加1。

#include <iostream>
#include <cstdio>
using namespace std;
const int N=100005;
const int mod=1000000007;
struct node{int id,v;}a[N];
int b[N],c[N],n;
bool cmp(node a,node b){return a.v<b.v;}
int sum(int x){int s=0;while(x>0)s+=c[x],s%=mod,x-=x&-x;return s;}
void updata(int x,int num){while(x<=n)c[x]+=num,c[x]%=mod,x+=x&-x;}
int main(){
while(scanf("%d",&n)!=EOF){
for(int i=0;i<=n;i++)b[i]=c[i]=0;
for(int i=1;i<=n;i++){
scanf("%d",&a[i].v);
a[i].id = i;
}
sort(a+1,a+n+1,cmp);
b[a[1].id]=1;
for(int i=2;i<=n;i++){
if(a[i].v!=a[i-1].v)b[a[i].id]=i;
else b[a[i].id]=b[a[i-1].id];
}
for(int i=1;i<=n;i++)updata(b[i],sum(b[i])+1);
printf("%d\n",sum(n));
}
return 0;
}

HDU 2227 Find the nondecreasing subsequences的更多相关文章

  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 (线段树)

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

  3. HDU 2227 Find the nondecreasing subsequences(DP)

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

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

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

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

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

  7. ACM学习历程——HDU2227 Find the nondecreasing subsequences(线段树 && dp)

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

  8. HDU 2227-Find the nondecreasing subsequences(dp+BIT优化)

    题意: 给你一个序列a[],求它的不降子序列的个数 分析: dp[i]表示以i结尾不降子序列的个数,dp[i]=sum(dp[j])+1(j<i&&a[j]<=a[i]); ...

  9. HDU2227Find the nondecreasing subsequences(树状数组+DP)

    题目大意就是说帮你给出一个序列a,让你求出它的非递减序列有多少个. 设dp[i]表示以a[i]结尾的非递减子序列的个数,由题意我们可以写出状态转移方程: dp[i] = sum{dp[j] | 1&l ...

随机推荐

  1. jQuery中 prop() attr()使用详解

    对于HTML元素本身就带有的固有属性,在处理时,使用prop方法.  对于HTML元素我们自己自定义的DOM属性,在处理时,使用attr方法. 在高版本的jquery引入prop方法后,什么时候该用p ...

  2. InnoDB的配置

    http://www.cnblogs.com/szx_rencaijob/archive/2010/04/28/1723211.html 推荐InnoDB的配置(1G内存情况,主要运行mysql服务器 ...

  3. C# async await 例子

    private static async void Worker() { Console.Write("main thread id is :{0}",Thread.Current ...

  4. Openstack命令收集

    查看rabbitmq 队列 rabbitmqctl list_queues 查看keystone的用户 keystone user-list 查看keystone endpoint keystone ...

  5. java对象的比较分析

    关于对象的比较我们可以通过以下三种手段来实现 一.利用"=="比较引用 Java中,当比较简单类型变量时用"==",只要两个简单类型值相等即返回ture,否则返 ...

  6. 关于oracle spfile配置文件问题

    $ORACLE_SID决定spfile dbs 默认 在启动Oracle数据库时报错,如下: [oracle@localhost ~]$ sqlplus / as sysdba SQL*Plus: R ...

  7. 九一八-->我逝去的青春

    九一八纪念馆 十二年前 30元一张门票 我毫不犹豫掏钱进去参观 你们笑我 钱少人傻 在东北的四年 从2001到2005 每年都感慨这一天 北国的秋色里 警钟长鸣 长鸣声中 有我逝去的青春 如今 三十而 ...

  8. java设计模式(二)单例模式 建造者模式

    (三)单例模式 单例模式应该是最常见的设计模式,作用是保证在JVM中,该对象仅仅有一个实例存在. 长处:1.降低某些创建比較频繁的或者比較大型的对象的系统开销. 2.省去了new操作符,减少系统内存使 ...

  9. 【LeetCode】Sum Root to Leaf Numbers

    题目 Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a num ...

  10. CF# 260 A. Laptops

    One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the m ...