hdu 2227Find the nondecreasing subsequences(树状数组+dp+离散化)
来源:互联网 发布:vb winhttp 编辑:程序博客网 时间:2024/06/05 00:22
题目链接:点击打开链接
题意描述:给定一个序列,找出其中递增子序列的数量?
解题思路:
1、dp[i]:表示以元素i结尾的子序列的数量,则d[j]=sum(d[i])+1;其中(j>=i且j的下标大于i)
2、此刻我们可以联想到树状数组,按数组下标从小到大的顺序插入元素,那么d[j]就等于sum(j)+1;
3、由于数据范围比较大,我们采用离散化处理即可
代码:
#include <cstdio>#include <algorithm>#include <cstring>#define MOD 1000000007using namespace std;struct node{ long long v; int pos; int rv;}d[100010];int n,rv;bool cmp1(node a,node b){ if(a.v==b.v) return a.pos<b.pos; return a.v<b.v;}bool cmp2(node a,node b){ return a.pos<b.pos;}int C[100010];int lowbit(int x){ return x&(-x);}int sum(int x){ long long ret=0; while(x>0){ ret+=C[x]; ret%=MOD; x-=lowbit(x); } return (int)ret;}void add(int x,int v){ while(x<=rv){ C[x]=(C[x]+(long long)v)%MOD; x+=lowbit(x); }}int main(){ while(scanf("%d",&n)==1){ for(int i=0;i<n;++i){ scanf("%I64d",&d[i].v); d[i].pos=i; } sort(d,d+n,cmp1); rv=0; for(int i=0;i<n;++i) d[i].rv=++rv; sort(d,d+n,cmp2); memset(C,0,sizeof(C)); long long ans=0; for(int i=0;i<n;++i){ add(d[i].rv,sum(d[i].rv-1)+1); ans+=sum(d[i].rv-1)+1; ans%=MOD; } printf("%d\n",(int)ans); } return 0;}
0 0
- 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
- hdu 2227 Find the nondecreasing subsequences(树状数组+DP)
- HDOJ 题目2227 Find the nondecreasing subsequences(树状数组,离散化,DP)
- HDU - 2227 Find the nondecreasing subsequences (树状数组 + 子序列 + 离散化)
- HDU2227 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)
- hdu2227---Find the nondecreasing subsequences(dp+树状数组)
- hdu-Find the nondecreasing subsequences(树状数组)
- 树状数组 hdu2227 Find the nondecreasing subsequences
- Box2d新系列 第八章 连接器(Joints)
- 关于常见的变量修饰符: const, static, extern, register, auto 的详细解释,使用场合以及注意事项
- 第4章 对象
- qml构建一个渐变色的窗口
- HBase之表的设计原则
- hdu 2227Find the nondecreasing subsequences(树状数组+dp+离散化)
- NOIP2015模拟1
- ZXing生成二维码,以及给二维码添加Logo
- Android Studio App设置线性布局LinerLayout控件垂直/水平方向排列
- Hibernate关联之 一对多外键单向关联
- oldssoj2677
- G语言图形内核库
- mysql 定时任务
- 抽象的方法能否同时是static、native、synchronized