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. 翻译:A Tutorial on the Device Tree (Zynq) -- Part V

    A Tutorial on the Device Tree (Zynq) -- Part V Application-specific data 之前提过,设备树中是一些特殊信息,这样一个驱动可以管理 ...

  2. 深入浅出 - Android系统移植与平台开发(九)- Android系统system_server及Home启动

    3.3 Zygote守护进程与system_server进程 Android的执行环境和Java执行环境有着本质的差别,在Android系统中每一个应用程序都是一独立的进程,当一个进程死掉时,不会影响 ...

  3. npm ERR! code EINTEGRITY npm ERR! sha1- 报错解决办法

    npm ERR! code EINTEGRITY npm ERR! sha1- 报错日志 npm ERR! code EINTEGRITY npm ERR! sha1-OGchPo3Xm/Ho8jAM ...

  4. Flume-ng-sdk源码分析

    Flume 实战(2)--Flume-ng-sdk源码分析 - mumuxinfei - 博客园 http://www.cnblogs.com/mumuxinfei/p/3823266.html

  5. poj 1180 Batch Scheduling (斜率优化)

    Batch Scheduling \(solution:\) 这应该是斜率优化中最经典的一道题目,虽然之前已经写过一道 \(catstransport\) 的题解了,但还是来回顾一下吧,这道题其实较那 ...

  6. 怎样在QML中利用Sprite来做我们须要的动画

    在游戏中动画的设计很中要. 在QML中,它提供了丰富的animation.可是有时我们须要对图像进行变化,就像放电影一样.在今天的这篇文章中,我们将设计一个能够变化图像的动画. 我们能够通过Qt所提供 ...

  7. android user用户版本提高adb权限【转】

    本文转载自:http://blog.csdn.net/liyongming1982/article/details/14108111 有的user用户版本的log 不全,且push/pull某些文件或 ...

  8. windows下安装composer流程

    1.php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 2. php -r &quo ...

  9. 机器学习 Hidden Markov Models 1

    Introduction 通常,我们对发生在时间域上的事件希望可以找到合适的模式来描述.考虑下面一个简单的例子,比如有人利用海草来预测天气,民谣告诉我们说,湿漉漉的海草意味着会下雨,而干燥的海草意味着 ...

  10. 内部锁之一:锁介绍(偏向锁 & 轻量级锁 & 重量级锁 & 各自优缺点及场景)

    一.内部锁介绍 上篇文章<Synchronized之二:synchronized的实现原理>中向大家介绍了Synchronized原理及优化锁.现在我们应该知道,Synchronized是 ...