Light OJ 1085 - All Possible Increasing Subsequences
2016-05-14 22:04
316 查看
题目
link给定一个序列, 求出上升子序列的总数。
分析
Dp[i] 表示序列 以 i 结尾的数目。可知 Dp[i]=∑Dp[x]+1
这是一个前缀和, 用树状数组维护。
Code
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn = 1e5 + 131; const LL MOD = 1e9 + 7; LL Num[maxn], A[maxn], B[maxn]; int n; int lowebit(int x) { return x&(-x); } LL Sum(int x) { LL ret = 0; while(x > 0) { ret = (ret + Num[x]) % MOD; x -= lowebit(x); } return ret; } void Update(int x, LL Val) { while(x <= n) { Num[x] = (Num[x] + Val) % MOD; x += lowebit(x); } } int main() { int t; scanf("%d",&t); for(int kase = 1; kase <= t; ++kase) { scanf("%d",&n); memset(Num, 0, sizeof(Num)); for(int i = 0; i < n; ++i) scanf("%lld",A+i), B[i] = A[i]; sort(A, A+n); int Max = unique(A, A+n)-A; for(int i = 0; i < n; ++i) { B[i] = lower_bound(A, A+Max, B[i])-A + 1; } //cout << "1" <<endl; for(int i = 0; i < n; ++i) { LL s = Sum(B[i]-1) + 1; //cout << "2" << " " <<B[i] <<endl; s %= MOD; Update(B[i], s); //cout << "3" <<endl; } LL Ans = Sum(n); printf("Case %d: %lld\n",kase, Ans); } return 0; }
相关文章推荐
- 详解Android应用中屏幕尺寸的获取及dp和px值的转换
- 基于Android中dp和px之间进行转换的实现代码
- Android中dip、dp、sp、pt和px的区别详解
- LFC1.0.0 版本发布
- Android dpi,dip,dp的概念以及屏幕适配
- Android px、dp、sp之间相互转换
- HP data protector软件学习1--基本角色与基本工作流程
- HP data protector软件学习2--软件组成与界面介绍
- android中像素单位dp、px、pt、sp的比较
- Android对px和dip进行尺寸转换的方法
- Android根据分辨率进行单位转换-(dp,sp转像素px)
- android 尺寸 dp,sp,px,dip,pt详解
- DP问题各种模型的状态转移方程
- POJ-1695-Magazine Delivery-dp
- nyoj-1216-整理图书-dp
- TYVJ1193 括号序列解题报告
- 对DP的一点感想
- TYVJ上一些DP的解题报告
- soj1005. Roll Playing Games
- 01背包问题