K上升序列总和

来源:互联网 发布:方便面怎么煮好吃知乎 编辑:程序博客网 时间:2024/05/16 11:50

Given an array of integers, find out number of ways in which you can select increasing subsequences of length k(k<=n).

for eg array is 1 4 6 2 5 & k=3
then the answer is :1 4 5, 1 2 5,1 4 6,
so ways are 3

int fun(int a[], int size, int K){int buf[size][K+1];memset(buf, 0, sizeof(buf));for (int i = 0; i < size; i++){buf[i][1] = 1;}int result = 0;for (int i = 1; i < size; i++){for (int j = 0; j < i; j++){if (a[i] > a[j]){for (int m = 1; m < K; m++){buf[i][m+1] += buf[j][m];}}}result += buf[i][K];}return result;}


0 0
原创粉丝点击