Description

For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. 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
题意:求长度为k+1的上升子序列有多少个
解法:sum=dp[0][k+1]+dp[1][k+1]+dp[2][k+1]+....dp[n][k+1]
dp[x][y]是x为上升子序列最后一个元素,长度为y的个数
用树状数组维护,更新的是num为上升子序列最后一个元素,长度为j时,加上num为上升子序列最后一个元素,长度为j-1时个数
最后求sum(n,m+1)总和
 #include <bits/stdc++.h>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            .h>
using namespace std;
#define ll long long
ll n,m;
ll dp[][];
ll bit(ll x)
{
return x&(-x);
}
void up(ll x,ll y,ll ans)
{
while(x<)
{
dp[x][y]+=ans;
x+=bit(x);
}
}
ll sum(ll x,ll y)
{
ll ans=;
while(x>)
{
ans+=dp[x][y];
x-=bit(x);
}
return ans;
}
int main()
{
cin>>n>>m;
up(,,);
for(int i=;i<=n;i++)
{
ll num;
cin>>num;
for(int j=m+;j>=;j--)
{
up(num,j,sum(num,j-));
}
}
cout<<sum(n,m+)<<endl;
return ;
}

Testing Round #12 C的更多相关文章

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

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

  2. Testing Round #12 A

    A. Divisibility time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

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

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

  4. Codeforces Testing Round #12 B. Restaurant 贪心

    B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...

  5. Codeforces Testing Round #12 A. Divisibility 水题

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

  6. Testing Round #12 A,B,C 讨论,贪心,树状数组优化dp

    题目链接:http://codeforces.com/contest/597 A. Divisibility time limit per test 1 second memory limit per ...

  7. Testing Round #12 B

    Description A restaurant received n orders for the rental. Each rental order reserve the restaurant ...

  8. “玲珑杯”ACM比赛 Round #12题解&源码

    我能说我比较傻么!就只能做一道签到题,没办法,我就先写下A题的题解&源码吧,日后补上剩余题的题解&源码吧!                                     A ...

  9. Codeforces Beta Round #12 (Div 2 Only)

    Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...

随机推荐

  1. Redis HyperLogLog及应用

    参考:http://www.runoob.com/redis/redis-hyperloglog.html Redis 在 2.8.9 之后的版本中,添加了 HyperLogLog 结构,用来做基数统 ...

  2. 高仿webqq做的一个webos桌面效果和web聊天工具,桌面效果完好,功能强大

    QQ技术交流群:159995692 /--------   暂时开放的測试       帐号/password:[88888888/1;666666/1]    ---------/ 正如大家所知的E ...

  3. 文件宝局域网传输/播放功能Windows10系统经验贴(感谢文件宝用户@卡卡罗特 和@24K 純情)

    本文由文件宝用户@卡卡罗特 和@24K 純情 两位用户提供,感谢二位. 先分享一个软件开发者的博客,http://www.cnblogs.com/flychen/也许里面的说明就能解决你的问题. 以下 ...

  4. HDU 6086 Rikka with String AC自动机 + DP

    Rikka with String Problem Description As we know, Rikka is poor at math. Yuta is worrying about this ...

  5. CSS3 (二)

    translate() 方法 通过 translate() 方法,元素从其当前位置移动,根据给定的 left(x 坐标) 和 top(y 坐标) 位置参数: 示例: div { transform: ...

  6. js-easyUI格式化时间

    formatter : function(value, row) { if(value != null){ var date = new Date(value); var y = date.getFu ...

  7. Node安装及搭建简单HTTP服务器

    注:本文安装系统为mac,windows及其他系统下载对应安装包 ,mac下载后的安装包为apk文件,windows为msi文件. 安装 1.在网上下载node安装包,官方网站2.双击下载文件,按步骤 ...

  8. 内核添加dts后,device和device_driver的match匹配的变动:通过compatible属性进行匹配【转】

    本文转载自:http://blog.csdn.net/ruanjianruanjianruan/article/details/61622053 内核添加dts后,device和device_driv ...

  9. ping 中的“TTL"是什么意思

    简单来说就是表示一个数据包在网络中可以跳跃的结点数据,当该数据为零时本数据包将被抛弃 详细解释看以下引用: TTL (although named as "time" to liv ...

  10. bzoj 1894 游戏

    题目大意: $n$个装备,每个装备有两个值,可以攻击该值对应的怪兽.每个装备最多用一次 每个怪兽被打一次之后就会死,每个怪兽可以被打当且仅当前面的都死了,求最多打多少个 思路: 很明显的二分图匹配,如 ...