###### 树状数组+dp（不太懂） Codeforces 597C
C. Subsequences
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
input
5 2
1
2
3
5
4

output
7


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long n;
long long dp[12][100010];
long long query(long long x,long long i)
{
long long ans=0;
while(i>0)
{
ans+=dp[x][i];
i-=i&-i;
}
return ans;
}
void update(long long x,long long i,long long num)
{
while(i<=n)
{
dp[x][i]+=num;
i+=i&-i;
}
return ;
}
int   main()
{
long long  k;
while(scanf("%lld%lld",&n,&k)!=EOF)
{
memset(dp,0,sizeof(dp));
for(long long  i=0; i<n; i++)
{
long long  x;
scanf("%lld",&x);
for(long long j=1; j<=k+1; j++)
{
long long res;
if(j==1)
res=1;
else res=query(j-1,x-1);
update(j,x,res);
}
}
printf("%lld\n",query(k+1,n));

}
}


#### CodeForces 597C 树状数组 dp

2017-01-16 10:29:36

#### codeforces 597C （树状数组+DP）

2016-08-19 22:37:45

#### Codeforces 597C(树状数组 + dp)

2015-11-20 12:24:54

#### 【Codeforces 597C】 Subsequences - DP 主席树

2015-12-21 21:16:20

#### Codeforces 597C Subsequences dp + 树状数组

2015-12-21 22:10:57

#### Subsequences CodeForces - 597C 树状数组 + dp

2016-12-14 13:16:08

#### Codeforces 703D 树状数组

2016-08-06 21:24:24

#### HDU - 3450 树状数组优化dp

2017-08-14 10:31:30

#### CodeForces - 293E Close Vertices（树上点分治 + 树状数组）

2017-08-09 18:03:04

#### Codeforces 597C Subsequences 【树状数组优化DP】

2015-11-13 21:57:02