您的位置:首页 > 产品设计 > UI/UE

codeforces 597C Subsequences

2015-11-23 19:09 861 查看

C. Subsequences

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<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=100005;
ll c[15][maxn];
int lowbit(int x)
{
return x&(-x);
}
void update(int st,ll val,int ed,int id)
{
for(int i=st;i<=ed;i+=lowbit(i))
c[id][i]+=val;
}
ll query(int st,int id)
{
ll res=0;
for(int i=st;i>0;i-=lowbit(i))
res+=c[id][i];
return res;
}
int main()
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
{
int tmp;
scanf("%d",&tmp);
update(tmp,1,n,0);
for(int i=1;i<=k;i++)
update(tmp,query(tmp-1,i-1),n,i);
}
printf("%I64d\n",query(n,k));
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: