mercredi 11 septembre 2019

how to delete the subset from array?

i had find all the subset of size k of given array with distinct elements.

i want to delete the subset from a generated subset that i got from the array.

how to remove the subset from all subset that is generated.

just give the idea to solve this type of problem.

#include <stdio.h> 
void combinationUtil(int arr[], int n, int r, int index, int data[], int i); 

void printCombination(int arr[], int n, int r) 
{ 
    int data[r]; 

    combinationUtil(arr, n, r, 0, data, 0); 
} 

void combinationUtil(int arr[], int n, int r, int index, 
                    int data[], int i) 
{ 
    if (index == r) { 
        for (int j = 0; j < r; j++) 
            printf("%d ", data[j]); 
        printf("\n"); 
        return; 
    } 
    if (i >= n) 
        return; 
    data[index] = arr[i]; 
    combinationUtil(arr, n, r, index + 1, data, i + 1); 

    combinationUtil(arr, n, r, index, data, i + 1); 
} 

int main() 
{
    int n,m;
    cin>>n>>m; 
    int arr[n];
    for(int i=0;i<n;i++){
        arr[i]=i;
    }
    printCombination(arr, n, m);

    return 0; 
} 

if input is 0 1 2 3 4
and output is
0 1 
0 2 
0 3 
0 4 
1 2 
1 3 
1 4 
2 3 
2 4 
3 4 


if i want to remove subset 0 2 and 2 3 how to solve this

Aucun commentaire:

Enregistrer un commentaire