思路:dp题,自己脑子太笨了,代码如下,提醒一下自己;
View Code
#include#include #include #include using namespace std; int s[110] = { 0}; int n = 0; int m = 0; int dp[110][110] = { 0}; int ans = 0; int main() { while(scanf("%d%d",&n,&m),n&&m) { ans = 0; memset(dp,0,sizeof(dp)); for(int i =1;i <= n; ++i) { scanf("%d",&s[i]); dp[i][1] = 1; for(int k = 2;k <= m; ++k) { dp[i][k] = 0; for(int j = 1;j < i; ++j) { if(s[j] < s[i]) dp[i][k] += dp[j][k-1]; } } ans = ans + dp[i][m]; } printf("%d\n",ans); } return 0; }