LightOJ 1085 - All Possible Increasing Subsequences 树状数组+离散
http://www.lightoj.com/volume_showproblem.php?problem=1085
题意:求一个序列的递增子序列个数。
思路:找规律可以发现,某个数作为末尾数的种类数为所有比它小的数的情况+1。使用树状数组查找即可。 C++11 的auto在Lightoj上不能用/.\
/** @Date : 2016-12-01-21.58
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version :
*/ #include<bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const int mod = 1000000007; int C[N], a[N]; void add(int p, int v)
{
while(p < N)
{
C[p] += v;
C[p] %= mod;
p += (-p) & p;
}
} int sum(int p)
{
int ans = 0;
while(p)
{
ans += C[p];
ans %= mod;
p -= (-p) & p;
}
return ans;
}
int main()
{
int T;
int cnt = 0;
cin >> T;
while(T--)
{
MMF(C);
int n;
scanf("%d", &n); map<int , int>q; for(int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
q[a[i]] = 1;
} int c = 1;
for(auto i = q.begin(); i != q.end(); i++)
i->se = c++; /*map<int , int>::iterator it;
for( it = q.begin(); it != q.end(); it++)
it->se = c++;*/
for(int i = 1; i <= n; i++)//找规律可以发现,某个数作为末尾数的种类数为所有比它小的数的情况+1
{
int x = q[a[i]];
add(x, sum(x - 1) + 1);
}
printf("Case %d: %d\n", ++cnt, sum(c - 1));
}
return 0;
}
LightOJ 1085 - All Possible Increasing Subsequences 树状数组+离散的更多相关文章
- Codeforces 597C. Subsequences (树状数组+dp)
题目链接:http://codeforces.com/contest/597/problem/C 给你n和数(1~n各不同),问你长为k+1的上升自序列有多少. dp[i][j] 表示末尾数字为i 长 ...
- [Codeforces261D]Maxim and Increasing Subsequence——树状数组+DP
题目链接: Codeforces261D 题目大意:$k$次询问,每次给出一个长度为$n$的序列$b$及$b$中的最大值$maxb$,构造出序列$a$为$t$个序列$b$连接而成,求$a$的最长上升子 ...
- CF597C Subsequences 树状数组 + 动态规划
设$f(i, j)$表示以$i$结尾的,长为$j$的上升子序列的数量 转移时用树状数组维护即可 复杂度为$O(kn \log n)$ 注:特判0 #include <cstdio> #in ...
- 【BZOJ】1818: [Cqoi2010]内部白点(树状数组+离散+特殊的技巧)
http://www.lydsy.com/JudgeOnline/problem.php?id=1818 这一题一开始我就看错了,bzoj的那个绝对值109简直坑人,应该是10^9,我直接写了个暴力. ...
- HDU-4605 Magic Ball Game 树状数组+离散+dfs
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4605 题意:给一颗树,每个节点有个权值w[u],每个节点只有两个儿子或者没有儿子,从根节点放下一个小球 ...
- bzoj 5055: 膜法师 树状数组+离散
先枚举每一个数,看它前面有几个比它小,算一下和为sum1,后面有几个比它大,算一下和为sum2,对答案的贡献为A[i]*sum1*sum2. 离散化后,树状数组就可以了. 就是倒着一边,顺着一边,统计 ...
- Codeforces Testing Round #12 C. Subsequences 树状数组
C. Subsequences For the given sequence with n different elements find the number of increasing s ...
- Codeforces Testing Round #12 C. Subsequences 树状数组维护DP
C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- hdu_5877_Weak Pair(离散+DFS+树状数组)
题目链接:hdu_5877_Weak Pair 题意: 给你一棵树,让你找有多少对满足那两个条件的weak pair 题解: 有人用Treap,我不会,然后我用树状数组+离散来替代Treap,用DFS ...
随机推荐
- HDU 4308 Saving Princess claire_(简单BFS)
求出不使用P点时起点到终点的最短距离,求出起点到所有P点的最短距离,求出终点到所有P点的最短距离. 答案=min( 不使用P点时起点到终点的最短距离, 起点到P的最短距离+终点到P的最短距离 ) #i ...
- [mongodb]child process failed, exited with error number 100
Run the following command first to start the mongo server mongod run --config /usr/local/etc/mongod. ...
- JS判断是IOS还是Android以及如何解决h5打包后在ios下内容与状态栏重叠问题
h5打包后在ios下内容与状态栏重叠问题: 1:知道设备的类型: var u = navigator.userAgent, app = navigator.appVersion; var isAndr ...
- Linux下误删文件恢复办法
恢复删除的文件 当误删除文件时,如果还有程序对此文件进行操作,那么可以通过lsof 命令恢复文件内容. 举例: 误删粗messages日志文件 [root@cdn ~]# cat /var/log/m ...
- Notes of the scrum meeting(12.12)
meeting time:19:30~20:30p.m.,December 12th,2013 meeting place:3号公寓一层 attendees: 顾育豪 ...
- 20145214 《Java程序设计》第4周学习总结
20145214 <Java程序设计>第4周学习总结 教材学习内容总结 继承 继承基本上就是避免多个类间重复定义共同行为.要避免在程序设计上出现重复,可以把相同的程序代码提升为父类. 关键 ...
- 自定义View 和 ViewGroup
一. 自定义View介绍 自定义View时, 继承View基类, 并实现其中的一些方法. (1) ~ (2) 方法与构造相关 (3) ~ (5) 方法与组件大小位置相关 (6) ~ (9) 方法与触摸 ...
- Ubuntu 12.04.1 LTS 升级 PHP 从5.3 到 5.5
#!/bin/bash # desc install php5.5 #add-apt-repository ppa:ondrej/php5 #apt-get install python-softwa ...
- Visio分类
以编程方式使用 Microsoft Office Visio 2003 ActiveX 控件 visio应用程序相关设置-选项-视图 visio应用程序相关设置-选项-常规 visio中相关设置-菜单 ...
- GDI & GDI+
GDI GDI绘图中的映射模式CDC::SetMapMode() GDI编程小结 GDI+ GDI+小例子 关于GDI+ GDI+编程小结