1 int a[100] = {68, 69, 54, 64, 68, 64, 70, 67, 78, 62, 98, 87}; //主序列; 2 int n = 1; //主序列元素个数; 3 int large = 1; //最长非连续递减子序列序列长度; 4 int num = 1; //最长非连续递减子序列序列数量; 5 int fun(int i, int n, int cnt) // i开始下标; n结束下标; cnt已找到递减序列长度; 6 { 7 if(i == n) 8 return 0; 9 10 for(int j=i+1; j<=n;j++) 11 { 12 if (a[i] > a[j]) 13 { 14 //cnt++; 15 fun(j, n, cnt+1); 16 17 if (cnt+1 > large) 18 { 19 large = cnt+1; 20 num = 1; 21 } 22 else if (cnt+1 == large) 23 { 24 num++; 25 } 26 } 27 } 28 29 return 0; 30 } 31 32 int _tmain(int argc, _TCHAR* argv[]) 33 { 34 for (int i=0; i<n; ++i) 35 { 36 fun(i, n-1, 1); 37 } 38 39 printf("\nlarge: %d \nnum:%d\n", large, num); 40 return 0; 41 }
原文:http://www.cnblogs.com/91Kesson/p/4182765.html