1 #include<stdio.h>
2 #include<string.h>
3 #include<algorithm>
4 using namespace std;
5 int n,c[305][10005],a[10005],b[10005];
6 int lowbit(int x)
7 {
8 return x&(-x);
9 }
10 int sum(int h,int x)
11 {
12 int ret=0;
13 while (x>0)
14 {
15 ret=(ret+c[h][x])%123456789;
16 x-=lowbit(x);
17 }
18 return ret;
19 }
20 void add(int h,int x,int d)
21 {
22 while (x<=n){
23 c[h][x]=(c[h][x]+d)%123456789;
24 x+=lowbit(x);
25 }
26 }
27 int main()
28 {
29 int m,i,j,cnt,x;
30 while (~scanf("%d%d",&n,&m))
31 {
32 for (i=1;i<=n;i++) { scanf("%d",&a[i]); b[i]=a[i]; }
33 sort(a+1,a+n+1);
34 cnt=unique(a+1,a+n+1)-a-1;
35 for (i=1;i<=n;i++)
36 b[i]=lower_bound(a+1,a+cnt+1,b[i])-a;
37 memset(c,0,sizeof(c));
38 for (i=1;i<=n;i++)
39 for (j=0;j<m;j++)
40 {
41 if (j==0) x=1;
42 else x=sum(j,b[i]-1);
43 add(j+1,b[i],x);
44 }
45 x=sum(m,n);
46 printf("%d\n",x);
47 }
48 }
http://acm.hdu.edu.cn/showproblem.php?pid=4991