Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- It assumes the input comes in the format
- <target string>
- <number of strings you can select characters from>
- <string 1>
- ...
- <string n>
- Where each string has length at most 20
- */
- #include <bits/stdc++.h>
- using namespace std;
- int64_t n;
- string target;
- string s;
- int64_t MOD = 1000000007;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cin >> target >> n;
- map<pair<int64_t, char>, int64_t> chars_per_pos;
- for (int64_t i = 0; i < n; i++) {
- cin >> s;
- for (int64_t j = 0; j < s.size(); j++) {
- chars_per_pos[{j, s[j]}]++;
- }
- }
- int64_t total = 0;
- for (int64_t mask = 0; mask < (1 << 20); mask++) {
- if (__builtin_popcount(mask) != target.size()) {
- continue;
- }
- int64_t idx = 0;
- int64_t temp = 1;
- for (int64_t j = 0; j < 20; j++) {
- if (mask & (1 << j)) {
- temp = (temp * chars_per_pos[{j, target[idx]}]) % MOD;
- idx++;
- }
- }
- total = (total + temp) % MOD;
- }
- cout << total << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement