For the given sequence with n different elements find the number of increasing subsequences with k + 1elements. It is guaranteed that the answer is not greater than 8·1018.

Input

First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the length of sequence and the number of elements in increasing subsequences.

Next n lines contains one integer ai (1 ≤ ai ≤ n) each — elements of sequence. All values ai are different.

Output

Print one integer — the answer to the problem.

Examples

Input
5 2
1
2
3
5
4
Output
7

题意:
给定包含了 n 个不同元素的序列,找出含有 k + 1 个元素的递增子序列有多少个。数据保证:答案不超过 8·1018 。
思路:
dp[a[i]][k]表示以a[i]为结尾,长度为k的子序列的个数.
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-); int a[maxn];
ll dp[maxn][]; ll bit[maxn][];
int lowbit(int x){
return x&-x;
} void update(int pos,ll val,int t){
while(pos<maxn){
bit[pos][t]+=val;
pos+=lowbit(pos);
}
} ll query(int pos,int t){
ll ans=;
while(pos){
ans+=bit[pos][t];
pos-=lowbit(pos);
}
return ans;
} int main()
{
int n,k;
scanf("%d%d",&n,&k);
k++; update(,,); for(int i=;i<=n;i++){
scanf("%d",&a[i]);
a[i]++;
for(int j=;j<=k;j++){
ll ans=query(a[i]-,j-);//a[i]-1防止自己接自己
dp[a[i]][j]=ans;
update(a[i],dp[a[i]][j],j);
}
}
ll ans=;
for(int i=;i<=n+;i++){
ans+=dp[i][k];
}
printf("%lld\n",ans); return ;
}

CodeForces - 597C Subsequences (树状数组+动态规划)的更多相关文章

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

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

  2. codeforces 597C (树状数组+DP)

    题目链接:http://codeforces.com/contest/597/problem/C 思路:dp[i][j]表示长度为i,以j结尾的上升子序列,则有dp[i][j]= ∑dp[i-1][k ...

  3. CF597C Subsequences 树状数组 + 动态规划

    设$f(i, j)$表示以$i$结尾的,长为$j$的上升子序列的数量 转移时用树状数组维护即可 复杂度为$O(kn \log n)$ 注:特判0 #include <cstdio> #in ...

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

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

  5. Sereja and Brackets CodeForces - 380C (树状数组+离线)

    Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in ...

  6. CodeForces 371D Vessels(树状数组)

    树状数组,一个想法是当往p注水时,认为是其容量变小了,更新时二分枚举,注意一些优化. #include<cstdio> #include<iostream> #include& ...

  7. Mishka and Interesting sum Codeforces Round #365 (树状数组)

    树状数组,与Turing Tree类似. xr[i]表示从1到i的抑或,树状数组维护从1到i每个数只考虑一次的异或,结果为sum(r) ^ sum(l) ^ xr[r] ^ xr[l] 其中xr[r] ...

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

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

  9. Codeforces 1096F(dp + 树状数组)

    题目链接 题意: 对于长度为$n$的排列,在已知一些位的前提下求逆序对的期望 思路: 将答案分为$3$部分 $1.$$-1$与$-1$之间对答案的贡献.由于逆序对考虑的是数字之间的大小关系,故假设$- ...

  10. DNA Evolution CodeForces - 828E(树状数组)

    题中有两种操作,第一种把某个位置的字母修改,第二种操作查询与[L, R]内与给出字符串循环起来以后对应位置的字母相同的个数.给出的字符串最大长度是10. 用一个四维树状数组表示 cnt[ATCG的编号 ...

随机推荐

  1. transform旋转,平移,缩放,扭曲 斜切

    transform  改变rotate 旋转translate  位移scale 缩放 skew  斜切变形 记得兼容性:-webkit-   -moz-    -ms-     -o- transf ...

  2. [代码笔记]JS保持函数单一职责,灵活组合

    比如下面的代码,从服务端请求回来的订单数据如下,需要进行以下处理1.根据 status 进行对应值得显示(0-进行中,1-已完成,2-订单异常)2.把 startTime 由时间戳显示成 yyyy-m ...

  3. weblogic patch log显示

    如何在WebLogic 12.1.3 版本的 server log 中显示 opatch 的补丁信息? 打补丁  patch 23558563 之后. 需要在 JAVA_OPTIONS 中添加如下参数 ...

  4. java压缩指定目录下的所有文件和文件夹的代码

    将代码过程较好的代码段备份一下,下边资料是关于java压缩指定目录下的所有文件和文件夹的代码,希望对码农有帮助. String sourceDir="E:\test";int pa ...

  5. PDF转图片工具

    点击下载( 提取码:1ll1 ) 软件功能基于mupdf,UI使用wxpython开发 功能: 支持pdf转图片,图片格式png 支持批量转换 使用: 第一步,点击按钮添加文档到列表,或直接将待转换文 ...

  6. SpringBoot 集成Apache Kafak 消息队列

    Kafka is a distributed,partitioned,replicated commit logservice.它提供了类似于JMS的特性,但是在实现上完全不同,此外它并不是JMS规范 ...

  7. 好代码是管出来的——使用GitHub实现简单的CI/CD

    软件开发一般来说是一项团队作业,在本系列文章开始就提到过软件的编码是由一个团队“并行”完成的,为了保证编码任务正常完成,首先引入版本控制工具来完成代码管理,为了保证代码质量引入了代码分析器以及代码测试 ...

  8. SQLServer之创建Transact-SQL游标

    什么是游标 结果集,结果集就是select查询之后返回的所有行数据的集合. 游标则是处理结果集的一种机制吧,它可以定位到结果集中的某一行,多数据进行读写,也可以移动游标定位到你所需要的行中进行操作数据 ...

  9. Win 10 无法打开内核设备“\\.\Global\vmx86”问题

    Win 10操作系统, VMWareWorkstation10 无法打开内核设备"\\.\Global\vmx86": 系统找不到指定的文件.你想要在安装 VMware Works ...

  10. storm ui 网页一直出现提示loading summary

    在更换了一次storm的版本之后:访问 http://mini1:8080/index.html 来查看storm的运行情况,但是出现了网页一直出现提示loading summary,但是通过透明的弹 ...