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 ...
随机推荐
- Applied Nonparametric Statistics-lec3
Ref: https://onlinecourses.science.psu.edu/stat464/print/book/export/html/4 使用非参数方法的优势: 1. 对总体分布做的假设 ...
- STM32的IAP方案
from: http://bbs.eeworld.com.cn/thread-294115-1-1.html 几乎所有的同类书籍都介绍综合性的应用示例如“万年历 + 温度显示 + 闹钟响铃 + 计 ...
- HUD:4405-Aeroplane chess(期望飞行棋)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- 【MySQL】MySQL备份和恢复
一.为什么要备份数据 在生产环境中我们数据库可能会遭遇各种各样的不测从而导致数据丢失, 大概分为以下几种. 硬件故障 软件故障 自然灾害 黑客攻击 误操作 (占比最大) 所以, 为了在数据丢失之后能够 ...
- 编译参数-ObjC的说明
一些第三方库里对系统库的类加了 category , 这时,就需要使用编译参数: -ObjC ,这样第三方库中对系统类作的扩展方法才能在工程中使用. 但是使用 -Objc 后,会产生两个问题: 1 . ...
- 递归函数的写法(以strcpy函数为例)
1. 递归函数模板 递归的前提是,找到一个公共子问题(或公共操作),然后将该函数构造为递归函数. retType function( ... ) { 结束条件 { [处理] 返回 } 递归条件 { [ ...
- XDEBUG 远程调试
我的PHP环境是安装在虚拟机中.真机系统用的是windows.那么我要用XDEBUG调试代码,就得用XDEBUG的远程调试功能. 首先要给远程环境中安装XDEBUG扩展,具体方法:http://www ...
- javascript学习笔记-数据类型
一 数据类型 基本类型:undefined,null,boolean,number,string 保存在栈内存中 占用空间固定 变量直接从栈内存中存取的是该值 引用类型: ...
- C#技术点
程序员的基本内功.操作系统,数据结构,网络协议,架构 mysql存储引擎,索引? 分布式技术一致性? 缓存系统/中间件技术/NoSql? 锁与线程切换? 排序,链表,hash_map?
- 【转】参照protobuf,将json数据转换成二进制在网络中传输。
http://blog.csdn.net/gamesofsailing/article/details/38335753?utm_source=tuicool&utm_medium=refer ...