卡常题解
2024-12-08 16:05:05
发布于:湖南
25阅读
0回复
0点赞
题解如下:
#include <iostream>
#include <vector>
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
using namespace std;
bool f(const vector<vector<long long>>& d, const vector<long long>& n, long long m, const vector<long long>& t) {
for (size_t k = 0; k < n.size(); ++k) {
if (t[k] < n[k]) {
return false;
}
}
return true;
}
bool g(vector<vector<long long>>& d, vector<long long>& n, long long x, long long y) {
vector<bool> dp(1 << x, false);
dp[0]=true;
vector<long long> t(y, 0);
for (long long i = 0; i < x; ++i) {
for (long long j = 0; j < y; ++j) {
t[j]+=d[i][j];
}
}
if (f(d, n, 0, t)) {
return true;
}
for (long long m = 1; m < (1 << x); ++m) {
vector<long long> t(y, 0);
for (long long i = 0; i < x; ++i) {
if (m & (1 << i)) {
for (long long j = 0; j < y; ++j) {
t[j]+=d[i][j];
}
}
}
dp[m]=false;
for (long long subm = m; subm > 0; subm = (subm - 1)&m) {
if (dp[subm] && f(d, n, subm, t)) {
dp[m]=true;
break;
}
}
}
return dp[(1 << x)-1];
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(0);
long long x, y;
cin >> x >> y;
vector<long long> n(y);
for (long long i = 0; i < y; ++i) {
cin >> n[i];
}
vector<vector<long long>> d(x, vector<long long>(y));
for (long long i = 0; i < x; ++i) {
for (long long j = 0; j < y; ++j) {
cin >> d[i][j];
}
}
if (g(d, n, x, y)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
全部评论 1
有这么麻烦吗?
2024-12-08 来自 浙江
0没有,就是想装一下(
2024-12-08 来自 湖南
06
2024-12-08 来自 浙江
0
有帮助,赞一个