Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning (disable : 4996)
- #include<stdlib.h>
- #include<stdio.h>
- int result = 0;
- int contains(const int helper[100][2], const int lengthHelper, const int number, const int index) {
- for (int i = 0; i < lengthHelper; i++) {
- if (number == helper[i][0] && index == helper[i][1]) {
- return 1;
- }
- }
- return 0;
- }
- int lenghtOfStrictlyGrowingSubsequence(const int* arr, const int helper[100][2], const int length, const int lHelper) {
- int sumLength = 0;
- int biggest = 0;
- int arrs[100] = { 0 };
- int it = 0;
- for (int i = 0; i < length; i++) {
- if (contains(helper, lHelper, arr[i], i) == 0) {
- arrs[it++] = arr[i];
- }
- }
- for (int i = 0; i < length - lHelper - 1; i++) {
- if (arrs[i] < arrs[i + 1]) {
- ++sumLength;
- }
- else {
- if (sumLength > biggest) biggest = sumLength;
- sumLength = 0;
- }
- }
- if (biggest < sumLength) biggest = sumLength;
- return biggest;
- }
- void printCombinations(int* arr, int helper[100][2], int length, int subsetLength, int index, int iterate) {
- if (index == subsetLength) {
- if (index == subsetLength) {
- int sum = lenghtOfStrictlyGrowingSubsequence(arr, helper, length + 1, subsetLength);
- ++sum;
- if (sum > result) result = sum;
- }
- return;
- }
- if (iterate > length) return;
- helper[index][0] = arr[iterate];
- helper[index][1] = iterate;
- printCombinations(arr, helper, length, subsetLength, index + 1, iterate + 1);
- printCombinations(arr, helper, length, subsetLength, index, iterate + 1);
- }
- int main(int argc, char* argv[]) {
- int length = 0;
- int subsets = 0;
- scanf("%d", &subsets);
- scanf("%d", &length);
- int* arr = (int*)malloc(sizeof(int) * length);
- int helper[100][2];
- for (int i = 0; i < 100; i++)
- {
- helper[i][0] = 0 ;
- helper[i][1] = 0;
- }
- for (int i = 0; i < length; i++)
- scanf("%d", &arr[i]);
- printCombinations(arr, helper, length - 1, subsets, 0, 0);
- printf("%d", result);
- free(arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement