Advertisement
Stoycho_KK

Untitled

Oct 22nd, 2021
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.95 KB | None | 0 0
  1. #pragma warning (disable : 4996)
  2.  
  3. #include<stdlib.h>
  4. #include<stdio.h>
  5.  
  6. int result = 0;
  7.  
  8. int contains(const int helper[100][2], const int lengthHelper, const int number, const int index) {
  9.     for (int i = 0; i < lengthHelper; i++) {
  10.         if (number == helper[i][0] && index == helper[i][1]) {
  11.             return 1;
  12.         }
  13.     }
  14.     return 0;
  15. }
  16.  
  17. int lenghtOfStrictlyGrowingSubsequence(const int* arr, const int helper[100][2], const int length, const int lHelper) {
  18.     int sumLength = 0;
  19.     int biggest = 0;
  20.  
  21.     int arrs[100] = { 0 };
  22.     int it = 0;
  23.  
  24.     for (int i = 0; i < length; i++) {
  25.         if (contains(helper, lHelper, arr[i], i) == 0) {
  26.             arrs[it++] = arr[i];
  27.         }
  28.     }
  29.  
  30.     for (int i = 0; i < length - lHelper - 1; i++) {
  31.         if (arrs[i] < arrs[i + 1]) {
  32.             ++sumLength;
  33.         }
  34.         else {
  35.             if (sumLength > biggest) biggest = sumLength;
  36.             sumLength = 0;
  37.         }
  38.     }
  39.  
  40.     if (biggest < sumLength) biggest = sumLength;
  41.  
  42.     return biggest;
  43. }
  44.  
  45. void printCombinations(int* arr, int helper[100][2], int length, int subsetLength, int index, int iterate) {
  46.     if (index == subsetLength) {
  47.         if (index == subsetLength) {
  48.             int sum = lenghtOfStrictlyGrowingSubsequence(arr, helper, length + 1, subsetLength);
  49.             ++sum;
  50.             if (sum > result) result = sum;
  51.         }
  52.         return;
  53.     }
  54.  
  55.     if (iterate > length) return;
  56.  
  57.     helper[index][0] = arr[iterate];
  58.     helper[index][1] = iterate;
  59.     printCombinations(arr, helper, length, subsetLength, index + 1, iterate + 1);
  60.     printCombinations(arr, helper, length, subsetLength, index, iterate + 1);
  61.  
  62. }
  63.  
  64. int main(int argc, char* argv[]) {
  65.     int length = 0;
  66.     int subsets = 0;
  67.  
  68.     scanf("%d", &subsets);
  69.     scanf("%d", &length);
  70.  
  71.     int* arr = (int*)malloc(sizeof(int) * length);
  72.     int helper[100][2];
  73.     for (int i = 0; i < 100; i++)
  74.     {
  75.         helper[i][0] =  0 ;
  76.         helper[i][1] = 0;
  77.     }
  78.  
  79.     for (int i = 0; i < length; i++)
  80.         scanf("%d", &arr[i]);
  81.  
  82.  
  83.     printCombinations(arr, helper, length - 1, subsets, 0, 0);
  84.  
  85.     printf("%d", result);
  86.  
  87.     free(arr);
  88.  
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement