设$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 树状数组 + 动态规划的更多相关文章

  1. HDU 4247 Pinball Game 3D(cdq 分治+树状数组+动态规划)

    Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. Codeforces 597C. Subsequences (树状数组+dp)

    题目链接:http://codeforces.com/contest/597/problem/C 给你n和数(1~n各不同),问你长为k+1的上升自序列有多少. dp[i][j] 表示末尾数字为i 长 ...

  3. [Scoi2014]方伯伯的玉米田 二维树状数组+动态规划

    考试最后半个小时才做这道题.十分钟写了个暴力还写挂了..最后默默输出n.菜鸡一只. 这道题比较好看出来是动规.首先我们要明确一点.因为能拔高长度任意的一段区域,所以如果从i开始拔高,那么一直拔高到n比 ...

  4. LightOJ 1085 - All Possible Increasing Subsequences 树状数组+离散

    http://www.lightoj.com/volume_showproblem.php?problem=1085 题意:求一个序列的递增子序列个数. 思路:找规律可以发现,某个数作为末尾数的种类数 ...

  5. ACM学习历程—SNNUOJ 1239 Counting Star Time(树状数组 && 动态规划 && 数论)

    http://219.244.176.199/JudgeOnline/problem.php?id=1239 这是这次陕西省赛的G题,题目大意是一个n*n的点阵,点坐标从(1, 1)到(n, n),每 ...

  6. CodeForces - 597C Subsequences (树状数组+动态规划)

    For the given sequence with n different elements find the number of increasing subsequences with k + ...

  7. Codeforces Testing Round #12 C. Subsequences 树状数组

    C. Subsequences     For the given sequence with n different elements find the number of increasing s ...

  8. BZOJ4881 线段游戏(二分图+树状数组/动态规划+线段树)

    相当于将线段划分成两个集合使集合内线段不相交,并且可以发现线段相交等价于逆序对.也即要将原序列划分成两个单增序列.由dilworth定理,如果存在长度>=3的单减子序列,无解,可以先判掉. 这个 ...

  9. Codeforces Testing Round #12 C. Subsequences 树状数组维护DP

    C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

随机推荐

  1. Computer Vision Resources

    Computer Vision Resources Softwares Topic Resources References Feature Extraction SIFT [1] [Demo pro ...

  2. 【NOIP题解】NOIP2017 TG D2T3 列队

    列队,NOIP2017 TG D2T3. 树状数组经典题. 题目链接:洛谷. 题意: Sylvia 是一个热爱学习的女孩子. 前段时间,Sylvia 参加了学校的军训.众所周知,军训的时候需要站方阵. ...

  3. 【bzoj题解】1001 狼抓兔子

    题目描述 现在小朋友们最喜欢"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形:   ...

  4. HaoZipC不是内部或外部命令

    Win7专业版,32位,HaoZip V3.2 将安装命令下HaoZipC.exe,HaoZip.dll,lang\HaoZipLang_chs.dll三个文件拷贝到C:\Windows\System ...

  5. Pytorch数据变换(Transform)

    实例化数据库的时候,有一个可选的参数可以对数据进行转换,满足大多神经网络的要求输入固定尺寸的图片,因此要对原图进行Rescale或者Crop操作,然后返回的数据需要转换成Tensor如: import ...

  6. 移动端默认meta标签

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><met ...

  7. java基础48 IO流技术(序列流)

    本文知识点目录: 1.SequenceInputStream序列流的步骤    2.实例    3.附录(音乐的切割与合并) 1.SequenceInputStream序列流的步骤 1.找到目标文件  ...

  8. 利用sys.dm_db_index_physical_stats查看索引碎片等数据

    我们都知道,提高sql server的数据查询速度,最有效的方法,就是为表创建索引,而索引在对数据进行新增,删除,修改的时候,会产生索引碎片,索引碎片多了,就需要重新组织或重新生成索引,以达到索引的最 ...

  9. Linux学习笔记:nohup & 后台任务

    在linux中,使用nohup xxx.sh &可以将前台任务变成后台任务执行,如果只使用&的话,在突然断网或者关闭启动终端时,内核会向后台任务发送sighup信号,从而导致后台任务停 ...

  10. 如何验证一个地址可否使用—— MmIsAddressValid函数分析

    又是一篇内核函数分析的博文,我个人觉得Windows的内核是最好的老师,当你想实现一个功能之前可以看看Windows内核是怎么做的,说不定就有灵感呢:) 首先看下官方的注释说明: /*++ Routi ...