CF597C Subsequences 树状数组 + 动态规划

设$f(i, j)$表示以$i$结尾的,长为$j$的上升子序列的数量
转移时用树状数组维护即可
复杂度为$O(kn \log n)$
注:特判0
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
namespace remoon {
#define ri register int
#define ll long long
#define tpr template <typename ra>
#define rep(iu, st, ed) for(ri iu = st; iu <= ed; iu ++)
#define drep(iu, ed, st) for(ri iu = ed; iu >= st; iu --)
#define gc getchar
inline int read() {
int p = , w = ; char c = gc();
while(c > '' || c < '') { if(c == '-') w = -; c = gc(); }
while(c >= '' && c <= '') p = p * + c - '', c = gc();
return p * w;
}
int wr[], rw;
#define pc(iw) putchar(iw)
tpr inline void write(ra o, char c = '\n') {
if(!o) pc('');
if(o < ) o = -o, pc('-');
while(o) wr[++ rw] = o % , o /= ;
while(rw) pc(wr[rw --] + '');
pc(c);
}
}
using namespace std;
using namespace remoon; #define sid 100050 int n, k, a[sid];
ll t[sid][]; inline void upd(int o, ll v, int k) {
for(ri i = o; i <= n + ; i += i & (-i))
t[i][k] += v;
} inline ll qry(int o, int k) {
ll ret = ;
for(ri i = o; i; i -= i & (-i))
ret += t[i][k];
return ret;
} inline void DP() {
ll ans = ;
if(k == ) ans = ;
rep(i, , n) {
upd(a[i], , );
rep(j, , k + ) {
ll S = qry(a[i] - , j - );
if(j == k + ) { ans += S; break; }
upd(a[i], S, j);
}
}
write(ans);
} int main() {
n = read(); k = read();
rep(i, , n) a[i] = read() + ;
DP();
return ;
}
CF597C Subsequences 树状数组 + 动态规划的更多相关文章
- HDU 4247 Pinball Game 3D(cdq 分治+树状数组+动态规划)
Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Codeforces 597C. Subsequences (树状数组+dp)
题目链接:http://codeforces.com/contest/597/problem/C 给你n和数(1~n各不同),问你长为k+1的上升自序列有多少. dp[i][j] 表示末尾数字为i 长 ...
- [Scoi2014]方伯伯的玉米田 二维树状数组+动态规划
考试最后半个小时才做这道题.十分钟写了个暴力还写挂了..最后默默输出n.菜鸡一只. 这道题比较好看出来是动规.首先我们要明确一点.因为能拔高长度任意的一段区域,所以如果从i开始拔高,那么一直拔高到n比 ...
- LightOJ 1085 - All Possible Increasing Subsequences 树状数组+离散
http://www.lightoj.com/volume_showproblem.php?problem=1085 题意:求一个序列的递增子序列个数. 思路:找规律可以发现,某个数作为末尾数的种类数 ...
- ACM学习历程—SNNUOJ 1239 Counting Star Time(树状数组 && 动态规划 && 数论)
http://219.244.176.199/JudgeOnline/problem.php?id=1239 这是这次陕西省赛的G题,题目大意是一个n*n的点阵,点坐标从(1, 1)到(n, n),每 ...
- CodeForces - 597C Subsequences (树状数组+动态规划)
For the given sequence with n different elements find the number of increasing subsequences with k + ...
- Codeforces Testing Round #12 C. Subsequences 树状数组
C. Subsequences For the given sequence with n different elements find the number of increasing s ...
- BZOJ4881 线段游戏(二分图+树状数组/动态规划+线段树)
相当于将线段划分成两个集合使集合内线段不相交,并且可以发现线段相交等价于逆序对.也即要将原序列划分成两个单增序列.由dilworth定理,如果存在长度>=3的单减子序列,无解,可以先判掉. 这个 ...
- Codeforces Testing Round #12 C. Subsequences 树状数组维护DP
C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
随机推荐
- 【译】第十二篇 Integration Services:高级日志记录
本篇文章是Integration Services系列的第十二篇,详细内容请参考原文. 简介在前一篇文章我们配置了SSIS内置日志记录,演示了简单和高级日志配置,保存并查看日志配置,生成自定义日志消息 ...
- spfa+floyed+最长路+差分约束系统(F - XYZZY POJ - 1932)(题目起这么长感觉有点慌--)
题目链接:https://cn.vjudge.net/contest/276233#problem/F 题目大意:给你n个房子能到达的地方,然后每进入一个房子,会消耗一定的生命值(有可能是负),问你一 ...
- 十大opengl教程
正文: 1. http://nehe.gamedev.net/ 这个是我觉得全世界最着名的OpenGL教程,并且有网友将其中48个教程翻译成了中文http://www.owlei.com/Dancin ...
- Go语言的各种Print函数
Go语言的各种Print函数 func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) func Pr ...
- Spring4笔记3--Bean的装配
Bean的装配: Bean 的装配,即 Bean 对象的创建.容器根据代码要求创建 Bean 对象后再传递给代码的过程,称为 Bean 的装配. 1. 创建Bean对象的方式: 1. 通过 getBe ...
- 高级C#信使(译) - Unity维基百科
高级C#信使 作者:Ilya Suzdalnitski 译自:http://wiki.unity3d.com/index.php/Advanced_CSharp_Messenger 描述 前言 Mis ...
- python网络编程-socketserver
一:socketserver简化了网络服务器的编写. 它有4个类:TCPServer,UDPServer,UnixStreamServer,UnixDatagramServer. 这4个类是同步进行处 ...
- 命令行执行Django脚本
命令行执行Django脚本 - #效仿manage.py加入的环境变量在脚本的文件加入 - #手动注册django所有的APP import sys,os ---------------------- ...
- 学习shell脚本之前的基础知识
日常的linux系统管理工作中必不可少的就是shell脚本,如果不会写shell脚本,那么你就不算一个合格的管理员.目前很多单位在招聘linux系统管理员时,shell脚本的编写是必考的项目.有的单位 ...
- HDU 3360 National Treasures(最小点覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3360 题目大意: 在一个n*m的格子中,每个格子有一个数值,-1表示空,其余表示财宝.每个财宝的数值转 ...