light oj1085All Possible Increasing Subsequences(树状数组+离散化+递推)
来源:互联网 发布:声音编辑软件 编辑:程序博客网 时间:2024/06/05 17:07
题意:
问你有多少个上升子序列。(题意很坑爹!)
分析:首先要离散化,因为数是int范围,而数最多时有1e5个。然后就是递推。类似于hdu5904的递推过程http://acm.hdu.edu.cn/showproblem.php?pid=5904
因为以一个数结尾的递增子序列只能来自上一个递增子序列的个数,即求所有以比结尾数小的数为结尾的子序列个数之和。(有点绕。。)
注意:在更新的时候就需要取模,如果考虑一个严格单调递增的序列,那么以第n个数为最后一个数结尾的单调递增子序列就会有2的n-1次个。所以需要在更新中就取模
#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>using namespace std;const int maxn = 100005;const long long mod = 1000000007;long long C[maxn];int a[maxn];struct Node{ int num, index;}node[maxn];bool cmp(Node p, Node q){ return p.num < q.num;}int lowbit(int lo){ return lo & (-lo);}void modify(int pos, long long value){ while(pos < maxn) { C[pos] = (value + C[pos]) % mod; pos += lowbit(pos); }}long long getsum(int pos){ long long sum = 0; while(pos > 0) { sum = (sum + C[pos]) % mod; pos -= lowbit(pos); } return sum % mod;}int main(){ int T, n; scanf("%d", &T); for(int t = 1; t <= T; t++) { scanf("%d", &n); long long ans = 0; int cnt = 1, pre; for(int i = 1; i <= n; i++) { scanf("%d", &node[i].num); node[i].index = i; } sort(node + 1, node + n + 1, cmp); a[node[1].index] = cnt; pre = node[1].num; for(int i = 2; i <= n; i++) { if(pre == node[i].num) a[node[i].index] = cnt; else { a[node[i].index] = ++cnt; pre = node[i].num; } } memset(C, 0, sizeof(C)); for(int i = 1; i <= n; i++) { int tem; tem = a[i]; tem++; int sum = getsum(tem - 1); ans += (sum + 1); modify(tem, sum + 1); } ans = ans % mod; printf("Case %d: %lld\n", t, ans); } return 0;}
0 0
- light oj1085All Possible Increasing Subsequences(树状数组+离散化+递推)
- lightoj 1085 All Possible Increasing Subsequences(递推式+离散化+树状数组维护)
- LightOJ 1085 All Possible Increasing Subsequences (DP&离散化&树状数组)
- lightoj1085 - All Possible Increasing Subsequences(树状数组)
- 1085 - All Possible Increasing Subsequences[树状数组]
- [树状数组]LightOJ 1085 - All Possible Increasing Subsequences
- Lightoj 1085 All Possible Increasing Subsequences (树状数组+DP)
- lightoj 1085 - All Possible Increasing Subsequences 【树状数组优化dp】
- Light OJ 1085 - All Possible Increasing Subsequences
- LightOJ 1085 - All Possible Increasing Subsequences(DP + 线段树 + 离散)
- lightoj1085 All Possible Increasing Subsequences
- hdu 2227 Find the nondecreasing subsequences (树状数组+dp+离散化)
- HDOJ 题目2227 Find the nondecreasing subsequences(树状数组,离散化,DP)
- HDU2227 Find the nondecreasing subsequences(树状数组+DP+离散化)
- hdu-2227-Find the nondecreasing subsequences(DP+离散化+树状数组)
- lightoj 1085 All Possible Increasing Subsequences
- hdu 2227 Find the nondecreasing subsequences【离散化+树状数组+DP思路】
- HDU - 2227 Find the nondecreasing subsequences (树状数组 + 子序列 + 离散化)
- 初识Hadoop之HDFS
- 由Docker开始畅想
- easyui-form表单提交combobox
- 7F算工资
- 知乎-如何进入BAT2
- light oj1085All Possible Increasing Subsequences(树状数组+离散化+递推)
- void*的详解
- Codeforces 730H Delete Them
- iOS 10-需要添加的权限配置
- C++ 异常—常见的错误处理问题
- SpringMVC中上传文件MultipartFile转File
- Android 特色开发,使用传感器
- 高级安全windows防火墙管理单元无法加载解决方法
- i+++i的解释及i+++++i的语法错误