bokitusol

mail@pastecode.io avatar
unknown
c_cpp
8 days ago
2.2 kB
3
Indexable
Never
#include <iostream>

using namespace std;

int n, m;
words[55][27];
int max_ans, sum_ans;
int check_bo[55];
int vsW[55];
int choose[27];
int sokitu;

void bokitu(int index_char) {
    for (int i = 1; i <= n; i++) {
        if (vsW[i] == 1) continue;
        if (words[i][index_char] == 1) {
            check_bo[i]++;
            if (check_bo[i] == 1) {
                sum_ans--;
            }
        }
    }
}

void update(int index_char) {
    for (int i = 1; i <= n; i++) {
        if (vsW[i] == 1) continue;
        if (words[i][index_char] == 1) {
            check_bo[i]--;
            if (check_bo[i] == 0) {
                sum_ans++;
            }
        }
    }
}


void backtrack(int index, int from) {
    if (index > sokitu - m) {
        if (sum_ans > max_ans) {
            max_ans = sum_ans;
        }
        return;
    }
    if (sum_ans < max_ans) {
        return;
    }
    
    
    for (int i = from; i <= 26; i++) {
        if (choose[i] == 1) {
            bokitu(i);
            backtrack(index + 1, i + 1);
            update(i);
        }
    }
    
}

void solve(int testcase) {
    
    cin >> n >> m;
    char tmp[55];
    int invalid = 0;
    sokitu = 0;
    for (int i = 0; i < 27; i++) {
        choose[i] = 0;
    }
    for (int i = 1; i <= n; i++) {
        vsW[i] = 0;
        for (int k = 0; k < 27; k++) {
            words[i][k] = 0;
        }
        cin >> tmp;
        int j = 0;
        int dem = 0;
        while (tmp[j] != '\0') {
            if (words[i][tmp[j] - 'a'] == 0) {
                words[i][tmp[j] - 'a'] = 1;
                dem++;
            }
            j++;
        }
        
        if (dem > m) {
            vsW[i] = 1;
            invalid++;
        }
        else {
            for (int k = 0; k < 27; k++) {
                if (word[i][k] == 1 && choose[k] == 0) {
                    sokitu++;
                    choose[k] = 1;
                }
            }
        }
        
    }
    
    max_ans = 0;
    sum_ans = n - invalid;
    
}


int main() {
    
    int t; cin >> t;
    
    for (int i = 1; i <= t; i++) {
        
        solve(i);
    }
    
    return 0;
}
Leave a Comment