View Code
1 #include<stdio.h> 2 #include<string.h> 3 #define int64 __int64 4 #define N 110 5 int64 dp[N][N],f[N]; 6 int main(){ 7 int64 n,i,j,k,p; 8 while(scanf("%I64d%I64d",&n,&k)!=EOF,n+k){ 9 memset(dp,0,sizeof(dp)); 10 for(i=1;i<=n;i++) { 11 scanf("%I64d",&f[i]); 12 dp[i][1]=1; 13 } 14 15 for(j=2;j<=k;j++){//长度 16 for(i=j;i<=n;i++){ 17 for(p=j-1;p<i;p++){ 18 if(f[i]>f[p]){ 19 //printf("dp[%I64d][%I64d]=%I64d dp[%I64d][%I64d]=%I64d\n",i,j,dp[i][j],p,j-1,dp[p][j-1]); 20 dp[i][j]+=dp[p][j-1];//+=是因为不断的更新同一个dp[i][j],dp[i][j]是累加起来的 21 //printf("dp[%I64d][%I64d]+=dp[%I64d][%I64d]\n ",i,j,p,j-1); 22 } 23 } 24 } 25 } 26 int64 sum=0; 27 for(i=k;i<=n;i++) 28 sum+=dp[i][k]; 29 printf("%I64d\n",sum); 30 } 31 return 0; 32 }