1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| #include<iostream> #include<cstdlib> #include<cstdio> #include<algorithm> #include<cstring> #define reg register #define N 10005 #define M 105 #define P 20140921 using namespace std; int A[N],B[N],cnt[N]; long long dp[M][N]; int n,m,mx;
void add(int x,int y) { while(x<=mx) { cnt[x]+=y; if(cnt[x]>=P)cnt[x]-=P; x+=x&-x; } } int query(int x) { int res=0; while(x) { res+=cnt[x]; if(res>=P)res-=P; x-=x&-x; } return res; }
int main() { reg int i,j; scanf("%d%d",&n,&m);
for(i=1; i<=n; i++) { scanf("%d",&A[i]); dp[1][i]=1; B[i]=A[i]; } if(m==1){ printf("%d\n",n); return 0; } sort(B+1,B+n+1); mx=unique(B+1,B+n+1)-B; for(i=1; i<=n; i++)A[i]=lower_bound(B+1,B+1+mx,A[i])-B+1; for(i=2; i<=m; i++) { memset(cnt,0,sizeof cnt); for(j=1; j<=n; j++) { dp[i][j]=query(A[j]-1); if(dp[i-1][j])add(A[j],dp[i-1][j]); } } reg long long ans=0; for(j=1; j<=n; j++) { ans+=dp[m][j]; if(ans>=P)ans-=P; } printf("%d\n",ans%P); return 0; }
|