题解:AT_abc358_c [ABC358C] Popcorn
一道子集枚举题。
我们用
时间复杂度
代码如下:
int n, m;
string str[13];
int popcount(int x) {
if (x == 0) return 0;
return popcount(x >> 1) + (x & 1);
}
int main() {
cin >> n >> m;
FORL(i, 1, n, 1) {
cin >> str[i];
}
int ans = 19;
FORL(i, 1, (1 << n) - 1, 1) {
string s = "";
FORL(j, 1, m, 1) s += " ";
FORL(j, 0, n - 1, 1) {
if ((i >> j) & 1) {
int now = n - j;
FORL(k, 0, m - 1, 1) {
if (str[now][k] == 'o') {
s[k] = 'o';
}
}
}
}
int cnt = 0;
FORL(j, 0, m - 1, 1) {
if (s[j] == 'o') ++cnt;
}
if (cnt == m) {
ans = min(ans, popcount(i));
}
}
write(ans);
}