abc 267 C
一个需要推公式的题
转化为图像大概是这样
abc 264 C
// 二进制数中 1 的个数
// int a = __builtin_popcount(x);
// 暴力枚举
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h1, w1, h2, w2;
cin >> h1 >> w1;
vector<vector<int>> A(h1, vector<int> (w1));
for (int i = 0; i < h1; i ++)
for (int j = 0; j < w1; j ++)
cin >> A[i][j];
cin >> h2 >> w2;
vector<vector<int>> B(h2, vector<int> (w2));
for (int i = 0; i < h2; i ++)
for (int j = 0; j < w2; j ++)
cin >> B[i][j];
int qh = h1 - h2, qw = w1 - w2;
for (int i = 0; i < 1 << h1; i ++)
{
if (__builtin_popcount(i) == qh)
{
for (int j = 0; j < 1 << w1; j ++)
if (__builtin_popcount(j) == qw)
{
int a = 0, b = 0, c = 0, d = 0;
bool ok = true;
for (; c < h2; c ++, a ++)
for (b = 0, d = 0; d < w2; b ++, d ++)
{
while (i >> a & 1) a ++ ;
while (j >> b & 1) b ++ ;
if (A[a][b] != B[c][d]) ok = false;
}
if (ok) {
cout << "Yes" << '\n';
return 0;
}
}
}
}
cout << "No" << '\n';
return 0;
}
abc 263 C
可以用 STL 强制排序
或者用二进制数的性质,一个数从大往小递减
当其中的 1 的个数相同时,数中的 1 变化的规律是,从左边高位聚集到集中在低位