Description
Given a sequence of N (1 ≤ N ≤ 10,000) integers S1, ..., SN (0 ≤ Si < 100,000), compute the number of increasing subsequences of S with length K (1 ≤ K ≤ 50 and K ≤ N); that is, the number of K-tuples i1, ..., iK such that 1 ≤ i1 < ... < iK ≤ N and Si1 < ... < SiK.
Input
The first line contains the two integers N and K. The following N lines contain the integers of the sequence in order.
Output
Print a single integer representing the number of increasing subsequences of S of length K, modulo 5,000,000.
#include<algorithm>
using namespace std;
#define maxn 10010
#define mod 5000000
int b[maxn],c[maxn][51],ans[maxn],a[maxn],n,m;
int id[100010];
int lowbit(int i)
{return i&(-i);}
int sum(int k,int i)
{
int s=0;
while(i)
{
s+=c[i][k];
s%=mod;
i-=lowbit(i);
}
return s;
}
void update(int k,int i,int val)
{
while(i<=maxn)
{
c[i][k]+=val;
c[i][k]%=mod;
i+=lowbit(i);
}
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
int i,j,t;
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
a[i]=b[i];
}
sort(a,a+n);
t=1;
id[a[0]]=t++;
for(i=1;i<n;i++)
if(a[i]!=a[i+1])
id[a[i]]=t++;
for(i=0;i<=n;i++)
ans[i]=1;
memset(c,0,sizeof(c));
for(i=1;i<=m;i++)
for(j=0;j<n;j++)
{
update(i,id[b[j]],ans[j]);
ans[j]=sum(i,id[b[j]]-1);
}
printf("%d\n",sum(m,n));//不是sum(m,id(n-1));
}
return 0;
}