题目链接
- 题意:
给两个矩阵i和j,只包含零和一。求是否能在j矩阵中选择若干行和若干列,使得他和i完全相同 - 分析:
这个题可以说是枚举的应用吧。先暴力枚举选取的行,之后就贪心匹配列即可
const int maxn = 25;
char smap[maxn][maxn], emap[maxn][maxn];
int num[(1 << 20) + 10], all;
int nowi,nowj;
void pre()
{
all = (1 << 20);
num[0] = 0;
FF(i, 1, all)
num[i] = num[i >> 1] + (i & 1);
}
int main()
{
int sn, sm, en, em;
RII(en, em);
REP(i, en)
RS(emap[i]);
RII(sn, sm);
REP(i, sn)
RS(smap[i]);
pre();
bool f = 0;
all = (1 << sn);
FF(s, 1, all)
{
if (num[s] != en) continue;
nowj = 0;
REP(j, sm)
{
nowi = 0;
REP(row, sn)
if ((1 << row) & s)
{
if (smap[row][j] != emap[nowi][nowj])
break;
nowi++;
}
if (nowi == en)
{
nowj++;
}
if (nowj >= em)
{
f = 1;
goto end;
}
}
}
end:;
if (f)
puts("Yes");
else
puts("No");
return 0;
}