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

题解:一开始我以为是动态规划,后来发现离散后树状数组很好做,首先,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. VS2015使用scanf报错解决方案

    版权声明:本文为博主原创文章,未经博主允许不得转载. 方法一:在程序最前面加#define _CRT_SECURE_NO_DEPRECATE: 方法二:在程序最前面加#define _CRT_SECU ...

  2. iOS网络请求之---GET和POST

    get是从服务器上获取数据,post是向服务器传送数据.前者把参数数据加在了将参数直接写在访问路径上.操作简单,不过容易被外界看到,安全性不高,地址最多255字节,后者则是将参数放到body里面.PO ...

  3. VS2013 快捷键乱掉如何修改回来

    比如 CTRL+E+C =注释 F6=重新生成解决方案 CTRL+D+Q=运行时快速监视 工具-->选项-->环境-->键盘-->应用以下其他键盘映射方案,下拉选择 Visua ...

  4. javaWeb项目带红色感叹号问题原因

    自建Userlibrary 中库中含有非.jar 文件.

  5. Intellij idea workflow 工作流插件安装

    idea提供支持的工作插件名字叫actiBPM,可以在idea中在线安装,但往往会连接不成功安装失败,所以这里提供了硬盘安装的方式: 首先是要去官网下载actiBPM插件,下载地址: http://p ...

  6. HTML中小问题

    1.a标签不添加href这个属性时,不会出现鼠标变成手型~

  7. h5的api dom全屏展示

    下面是完整的例子,暂不做分析 <!DOCTYPE html> <html> <head> <title> FullScreen API 演示</t ...

  8. Rem & Viewport

    Rem布局 rem就是给根元素设置一个基准值 然后其他元素都以这个基准值作为单位 那么就可以在不同的手机上做出相同比例的元素了 事实上和百分比是同样的道理 网易和淘宝的rem 参考 http://ww ...

  9. NodeJS 从0开始

    查看Node 基本配置$ npm config ls -l $npm help install将展开install的help文档 初始化目录 npm init 根据提示完成 将生成package.js ...

  10. Mysql 笔记:

    1:可以查看information_schema.index_statistics 来查看索引的使用信息.还可以使用pt-index-usage 这个工具来分析日志再结合explain 来分析使用的索 ...