HDU - 2227 Find the nondecreasing subsequences
2014-04-13 15:34
417 查看
题意:求不递减的子序列的个数
思路:跟昨天那题HDU-3030不同的是,昨天的是严格的递增的子序列数,稍微修改一下就行了
思路:跟昨天那题HDU-3030不同的是,昨天的是严格的递增的子序列数,稍微修改一下就行了
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define ll long long using namespace std; const int MOD = 1000000007; const int MAXN = 100010; ll arr[MAXN],n; int num[MAXN],sortNum[MAXN]; int lowbit(int x){ return x&(-x); } void update(int x,ll d){ while (x <= n){ arr[x] += d; arr[x] %= MOD; x += lowbit(x); } } ll sum(int x){ ll ans = 0; while (x > 0){ ans += arr[x]; ans %= MOD; x -= lowbit(x); } return ans; } int main(){ while (scanf("%lld",&n) != EOF){ memset(arr,0,sizeof(arr)); for (int i = 1; i <= n; i++){ scanf("%d",&num[i]); sortNum[i] = num[i]; } sort(sortNum+1,sortNum+1+n); for (int i = 1; i <= n; i++){ int index = lower_bound(sortNum+1,sortNum+1+n,num[i])-sortNum; ll temp = sum(index); update(index,temp+1); } cout << sum(n) << endl; } return 0; }
相关文章推荐
- 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
- HDOJ 2227 HDU 2227 Find the nondecreasing subsequences ACM 2227 IN HDU
- HDU 2227 Find the nondecreasing subsequences(DP)
- HDU-2227 Find the nondecreasing subsequences 树状数组+DP
- HDU 2227 Find the nondecreasing subsequences
- Find the nondecreasing subsequences HDU 2227
- 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_FindTheNondecreasingSubsequences
- hdu 2227 Find the nondecreasing subsequences【离散化+树状数组+DP思路】
- 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 (树状数组 + 子序列 + 离散化)