hdu 2227 Find the nondecreasing subsequences 树状数组+简单DP
来源:互联网 发布:博易大师软件 编辑:程序博客网 时间:2024/05/19 00:50
题意就不说了
有几个值得注意的地方,首先,数据范围太大,要离散化
有一个问题就是1 5 5
离散化后可能是1 3 2
本来应该是1 2 3的,就会出错
所以排序的时候加个按关键值排序,值相同时按id递增排序
View Code
#include<cstdio>
#include<algorithm>
using namespace std;
const int mod=1000000007;
const int maxn=100000;
struct node{
int num;
int id;
}a[maxn+10];
__int64 dp[maxn+10];
int num[maxn+10];
int cmp(node a,node b){
if(a.num!=b.num)
return a.num<b.num;
return a.id<b.id;
}
int lowbit(int x){
return x&-x;
}
void update(int x,__int64 d){
for(;x<=maxn;x+=lowbit(x)){
dp[x]+=d;
if(dp[x]>=mod) dp[x]-=mod;
}
}
__int64 sum(int x){
__int64 ans=0;
for(;x>0;x-=lowbit(x)){
ans+=dp[x];
if(ans>=mod) ans-=mod;
}
return ans;
}
int main(){
int n,i;
__int64 ans;
while(scanf("%d",&n)!=EOF){
ans=0;
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++){
scanf("%d",&a[i].num);
a[i].id=i;
}
sort(a+1,a+n+1,cmp);
for(i=1;i<=n;i++){
__int64 s=sum(a[i].id)+1;
update(a[i].id,s);
ans+=s;
if(ans>=mod) ans-=mod;
}
printf("%I64d\n",ans);
}
return 0;
}
- hdu 2227 Find the nondecreasing subsequences 树状数组+简单DP
- hdu 2227 Find the nondecreasing subsequences(树状数组+DP)
- hdoj 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思路】
- hdu 2227 Find the nondecreasing subsequences (树状数组+dp+离散化)
- hdu 2227Find the nondecreasing subsequences(树状数组+dp+离散化)
- hdu-2227-Find the nondecreasing subsequences(DP+离散化+树状数组)
- HDU 2227 Find the nondecreasing subsequences(DP)
- hdu2227---Find the nondecreasing subsequences(dp+树状数组)
- hdu-Find the nondecreasing subsequences(树状数组)
- 树状数组 hdu2227 Find the nondecreasing subsequences
- Find the nondecreasing subsequences--(树状数组)
- HDOJ 题目2227 Find the nondecreasing subsequences(树状数组,离散化,DP)
- HDU - 2227 Find the nondecreasing subsequences (树状数组 + 子序列 + 离散化)
- hdu 2227 Find the nondecreasing subsequences
- hdu 3577 线段树,成段更新 好题 查询区间的最大覆盖次数
- poj 2182 lost cows 树状数组,二分
- hdu 4031 attack 树状数组 线段树 两种做法
- hdu 3460 Ancient Printer
- hdu 4107 Gangster 线段树 成段更新
- hdu 2227 Find the nondecreasing subsequences 树状数组+简单DP
- poj 3667 Hotel 区间合并
- hdu 2757 广搜+优先队列
- hdu 1542 线段树 求面积并
- hdu 1225 求覆盖至少两次的区域的面积并
- hdu 1828 poj 1177 picture 求周长并
- poj 2677 双调欧几里得 动态规划
- 线段树 hdu 2871 memory control
- hdu 3016 man down