HDU2227 Find the nondecreasing subsequences(树状数组+DP+离散化)
来源:互联网 发布:江南大学网络教育好吗? 编辑:程序博客网 时间:2024/05/18 15:05
题意:给一串数字,求不下降子序列的个数。
思路:数据量大,简单dp O(n^2)会爆,想到用树状数组存储前面的结果。数据量不大,但数据范围大,先离散化处理。复杂度O(n*logn)。
//#include<bits/stdc++.h>#include<cstdio>#include<cmath>#include<set>#include<map>#include<queue>#include<stack>#include<vector>#include<string>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>#include<functional>#define inf 0x3f3f3f3f#define isLeapYear(x) x%100!=0 && x%4==0 || x%400==0 ? 1 : 0#define yearLen 5005using namespace std;typedef unsigned long long llu;typedef long long ll;const double PI=acos(-1.0);const double eps=1e-10;#define N 100000#define mod 1000000007#define CLR(x) memset(x,0,sizeof x)#define Lowbit(x) (x&(-x))#define Find(x,y) (Sum(x,y)-Sum(x-1,y)-Sum(x,y-1)+Sum(x-1,y-1))int bit[N+5],n,c[N+5],dp[N+5];/*计算前i项和*/int sum(int i){ int s=0; while(i>0){ s+=bit[i]; s%=mod; i-=Lowbit(i); } return s;}/*使第i项增加x*/void add(int i,int x){ /*N是i可能的最大值*/ while(i<=N){ bit[i]+=x; bit[i]%=mod; i+=Lowbit(i); }}int main(){ while(~scanf("%d",&n)){ CLR(bit); pair<int,int>p[N+5]; for(int i=1;i<=n;i++){ scanf("%d",&p[i].first); p[i].second=i; } //离散化 sort(p+1,p+n+1); for(int i=1;i<=n;i++){ c[p[i].second]=i; } for(int i=1;i<=n;i++){ dp[i]=sum(c[i]); add(c[i],dp[i]+1); } printf("%d\n",sum(N)); } return 0;}
0 0
- HDU2227 Find the nondecreasing subsequences(树状数组+DP+离散化)
- hdu2227---Find the nondecreasing subsequences(dp+树状数组)
- 树状数组 hdu2227 Find the nondecreasing subsequences
- hdu2227 Find the nondecreasing subsequences(dp+线段树or树状数组优化)
- hdu 2227 Find the nondecreasing subsequences (树状数组+dp+离散化)
- HDOJ 题目2227 Find the nondecreasing subsequences(树状数组,离散化,DP)
- hdu-2227-Find the nondecreasing subsequences(DP+离散化+树状数组)
- hdu 2227 Find the nondecreasing subsequences【离散化+树状数组+DP思路】
- hdu 2227Find the nondecreasing subsequences(树状数组+dp+离散化)
- HDU2227(Find the nondecreasing subsequences)
- hdu 2227 Find the nondecreasing subsequences(树状数组+DP)
- HDU2227:Find the nondecreasing subsequences
- Find the nondecreasing subsequences--(树状数组)
- Find the nondecreasing subsequences(数状数组+离散化+dp)
- HDU2227 - 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 (树状数组 + 子序列 + 离散化)
- 华为手机USB调试搜不到设备
- 类
- RecyclerView和ListView的异同
- 2016.10.5 普及总结 暨 2016 Aug.~Sep. 总结
- 类的继承
- HDU2227 Find the nondecreasing subsequences(树状数组+DP+离散化)
- C++函数模板
- 《机遇与挑战——中国机器人产业发展的深度思考》
- AsyncTask
- HTML、CSS、JS全拼
- 类的多态
- 排序算法总结
- 关于phpmyadmin的密码登录
- HDU 2601 An easy problem