#include #include #include #include #include #include #include #include #include #include #define M 105 using namespace std; struct bigint{ int A[50]; int len; bigint(){ memset(A,0,sizeof(A)); len=1; } }; bigint operator + (bigint a,bigint b){ bigint ans; ans.len=max(a.len,b.len); for(int j=0;j=10){ ans.A[j+1]+=ans.A[j]/10; ans.A[j]%=10; } } if(ans.A[ans.len]) ans.len++; return ans; } bigint dp[M][M]; int A[M]; void print(bigint a){ int j; for(j=a.len-1;j>=0;j--) printf("%d",a.A[j]); printf("\n"); } int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF){ int j,k,i; memset(dp,0,sizeof(dp)); for(j=1;j<=n;j++){ scanf("%d",&A[j]); dp[j][1].A[0]=1; dp[j][1].len=1; } for(j=1;j<=n;j++){ for(k=1;k=A[j]) continue; for(i=1;i<=k;i++){ dp[j][i+1]=dp[j][i+1]+dp[k][i]; } } } bigint ans; for(j=1;j<=n;j++) ans=ans+dp[j][m]; print(ans); } //system("pause"); return 0; }