Find the nondecreasing subsequences HDU 2227
来源:互联网 发布:数据库管理系统的发展 编辑:程序博客网 时间:2024/05/24 03:22
树状数组
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define maxn 100006int a[maxn];int n=maxn;struct Note{int val,ord;}b[maxn];bool cmp(Note a,Note b){return a.val<b.val;}int lowbit(int i){return i&(-i);}int Sum(int i){int sum=0;while(i>=1){sum=(sum+a[i])%1000000007;i-=lowbit(i);}return sum;}void Update(int i,int tem){while(i<=n){a[i]+=tem;a[i]=a[i]%1000000007;i+=lowbit(i);}}int main(){int m;int i;int c[maxn];int k;while(scanf("%d",&m)!=EOF){for(i=1;i<=m;i++){scanf("%d",&b[i].val);b[i].ord=i;}sort(b+1,b+m+1,cmp);memset(a,0,sizeof(a));c[b[1].ord]=1;for(i=2;i<=m;i++)//因为数值范围是2^32,所以做了个小处理,按照排序把数值缩小。{if(b[i].val>b[i-1].val)c[b[i].ord]=i;elsec[b[i].ord]=c[b[i-1].ord];}for(i=1;i<=m;i++){k=Sum(c[i]);Update(c[i],k+1);}printf("%d\n",Sum(m));}return 0;}
- hdu 2227 Find the nondecreasing subsequences
- Find the nondecreasing subsequences HDU 2227
- HDU 2227 Find the nondecreasing subsequences
- HDU - 2227 Find the nondecreasing subsequences
- HDU - 2227 Find the nondecreasing subsequences
- HDU 2227 Find the nondecreasing subsequences(DP)
- HDU 2227 Find the nondecreasing subsequences
- HDU find the nondecreasing subsequences
- hdu 2227 Find the nondecreasing subsequences(树状数组)
- 线段树 HDU 2227 Find the nondecreasing subsequences
- HDU 2227 Find the nondecreasing subsequences 树状数组
- hdu 2227 Find the nondecreasing subsequences 树状数组+简单DP
- HDU 2227 Find the nondecreasing subsequences (线段树)
- HDU--2227--Find the nondecreasing subsequences--线段树
- hdu 2227 Find the nondecreasing subsequences(树状数组+排序)
- hdu 2227 Find the nondecreasing subsequences(树状数组+DP)
- Find the nondecreasing subsequences
- HDOJ 2227 Find the nondecreasing subsequences
- 提炼数据 数据处理
- 如何规范.net中的js开发(1)概念篇(更新版)
- WebService 实例应用
- mysql数据库性能的十个参数(转)
- [125]Valid Palindrome
- Find the nondecreasing subsequences HDU 2227
- 最近实在太忙,博客暂停更新
- XMLHttpRequest post 传递多个参数及服务器端读取
- 用Java创建数组工具类ArrayTool
- 字典排序算法的实现
- 黑马程序员_类的加载器之学习心得
- DSPack视频调节
- 醉妆词
- 内核修改注册表