Light oj 1085 - All Possible Increasing Subsequences (简单dp + 离散化 + BIT)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1085
题意:
问你有多少个上升子序列。
思路:
dp[i]表示以第i个数结尾的上升序列数量。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
const int N = 1e5 + ;
int a[N];
int b[N], n;
LL bit[N], mod = 1e9 + ;
LL dp[N]; void add(int i, LL val) {
for( ; i <= n; i += (i&-i))
bit[i] += val;
} LL sum(int i) {
LL s = ;
for( ; i >= ; i -= (i&-i))
s += bit[i];
return s;
} int main()
{
int t;
scanf("%d", &t);
for(int ca = ; ca <= t; ++ca) {
scanf("%d", &n);
for(int i = ; i <= n; ++i) {
scanf("%d", a + i);
b[i] = a[i];
}
sort(b + , b + n + );
memset(bit, , sizeof(bit));
memset(dp, , sizeof(dp));
for(int i = ; i <= n; ++i) {
a[i] = lower_bound(b + , b + n + , a[i]) - b;
dp[i]++;
}
for(int i = ; i <= n; ++i) {
dp[i] += sum(a[i] - );
dp[i] %= mod;
add(a[i], dp[i]);
}
LL ans = ;
for(int i = ; i <= n; ++i) {
ans += dp[i];
ans %= mod;
}
printf("Case %d: %lld\n", ca, ans);
}
return ;
}
Light oj 1085 - All Possible Increasing Subsequences (简单dp + 离散化 + BIT)的更多相关文章
- Light OJ 1085 - All Possible Increasing Subsequences
题目 link 给定一个序列, 求出上升子序列的总数. 分析 Dp[i] 表示序列 以 i 结尾的数目. 可知 Dp[i]=∑Dp[x]+1 这是一个前缀和, 用树状数组维护. Code #inclu ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖
题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...
- LightOJ 1085 - All Possible Increasing Subsequences 树状数组+离散
http://www.lightoj.com/volume_showproblem.php?problem=1085 题意:求一个序列的递增子序列个数. 思路:找规律可以发现,某个数作为末尾数的种类数 ...
- Light OJ 1011 - Marriage Ceremonies(状压DP)
题目大意: 有N个男人,和N个女人要互相匹配,每个男人和每个女人有个匹配值. 并且匹配只能是1对1的. 问所有人都匹配完成,最大的匹配值是多少? 状压DP,暴力枚举就OK了, 这个题目略坑,因为他 ...
- Light OJ 1032 - Fast Bit Calculations(数位DP)
题目大意: 一个数字把他看成二进制数字,数字里又会一些相邻的1,问从0到n至间所有相邻1的总和是多少? 分解成2进制数字,然后数位DP就行了. ======================== ...
- Light OJ 1025 - The Specials Menu(区间DP)
题目大意: 给你一个字符串,问有多少种方法删除字符,使得剩下的字符是回文串. 有几个规定: 1.空串不是回文串 2.剩下的字符位置不同也被视为不同的回文串.如:AA有三种回文串 A, A, A ...
- [LeetCode] Increasing Subsequences 递增子序列
Given an integer array, your task is to find all the different possible increasing subsequences of t ...
- SnackDown Longest Increasing Subsequences 构造题
Longest Increasing Subsequences 题目连接: https://www.codechef.com/SNCKPA16/problems/MAKELIS Description ...
随机推荐
- vue创建路由,axios前后台交互,element-ui配置使用,django contentType组件
vue中创建路由 每一个vue组件都有三部分组成 template:放html代码 script:放js相关 style:放css相关 vue中创建路由 1.先创建组件 Course.vue 2.ro ...
- Django之URL
URL是用户请求路径与views视图处理函数的一个映射 简单的路由配置及实现 这里是pycharm编辑开发为例,新建的django项目,会在url.py下自动生成这样一段代码: from django ...
- LeetCode(260) Single Number III
题目 Given an array of numbers nums, in which exactly two elements appear only once and all the other ...
- [solution]腾讯TEG_计算广告组_算法题
度娘笔试归来,题目实打实的,感觉真心不易,上百号人就抢那么几个坑......只恨自己平时积累太少啊~ 故曝一道鹅厂面试用的算法题(当时我就死在了这题上),来为度娘家攒一下RP~ 题目: 对于长度为N的 ...
- Ubuntu简单指令和热键的学习
Ubuntu查看本机版本的方法 sudo lsb_release -a即可 注销linux: 输入:exit 注意,离开系统不是关机,基本上,linux本身已经有相当多的工作进行,所以你离开时,这次这 ...
- luogu2394 yyy loves Chemistry I
练习 #include <iostream> #include <cstdio> using namespace std; long double a; int main(){ ...
- 玩App怎么赚钱(二)
紧接上篇文章,谈到App前赚钱的一些门道,其实还有很多了,需要你自己去挖掘App到底有什么价值.有价值的东西就能形成交易,而交易的过程中是用金钱作为流通手段,所以说赚钱没那么高大上,它的本质就是价值的 ...
- 2016-2017 ACM Central Region of Russia Quarterfinal Programming Contest BHanoi tower
B Hanoi tower It has become a good tradition to solve the “Hanoi tower” puzzle at programming contes ...
- Thanks for your encourage!
将近三个月的学习,我的努力换回了代表荣誉的小黄衫,这令我很开心啊...我想是不是要写点什么来表达自己的心情呢=,= 于是就有了以下文字ahhhhhh... 学习心得: (1)学习中总会有失败和成功, ...
- PTA 11-散列4 Hard Version (30分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/680 5-18 Hashing - Hard Version (30分) Given ...