版本比较
10.17二进制枚举总结
正文
增加 17 行删除 17 行
14 行未改动15161718192021222357 行未改动8182838485868788899091929394959697989910010110210310410557 行未改动16316416516616716816917017117217317417517613 行未改动19019119219319419519619719819920020112 行未改动2142152162172182192202212223 行未改动2262272282292302312322332344 行未改动23924024124224324424524624711 行未改动25926026126226326426526626714 行未改动你希望计划成功率最大。因此,你需要选出合适的人士,来参与到你的宏图伟业中。## 输入格式第一行,两个正整数 $n, k$。分别表示供你挑选的人的数量,以及能力的种类数。接下来 $n$ 行,每行表示每个人拥有的能力。这一行首先有一个整数 $c$,表示该人士拥有多少种能力;接下来是 $c$ 个 $[1, k]$ 之间的正整数,表示该人士拥有哪些能力。## 输出格式57 行未改动### 输入 #4```21 60003 60 27 4801 482 52 142 4 31002 28 432 6 3101 73 45 6 4801 5102 28 202 37 511 853 59 39 29 23 53 27 13 16 44 34 38 24 9 32 58 54 31 1 7 45 3 30 36 17 48 42 22 18 21 6 11 25 33 37 52 10 60 49 57 2 28 8 14 5 47 4 41 35 43 50 46 26 1257 行未改动using namespace std;int n, k;long long a[50], s, u, ans;int main() {cin >> n >> k;for (int i = 1; i <= n; i++) {long long c, x; cin >> c;while(c--) cin >> x, a[i] |= long(pow(2, k - x));}long long len = 1 << n;for (int i = 0; i < len; i++) {long long sum = 0;for (int j = 0; j < n; j++)if (i >> j & 1) sum ^= a[j + 1];13 行未改动int h[1000007];int main() {cin >> n >> b;for (int i = 1; i <= n; i++) cin >> h[i];int len = 1 << n;for (int i = 0; i < len; i++) {int s = 0;for (int j = 0; j < n; j++)if (i >> j & 1) s += h[j + 1];if (s >= b) ans = min(ans, s - b);}cout << ans << endl;12 行未改动cin >> n >> m >> k >> r;for (int i = 1; i <= n; i++) cin >> t[i];for (int i = 1; i <= m; i++) cin >> tt[i];for (int i = 1; i <= m; i++) cin >> s[i];int len = 1 << m;for (int i = 0; i < len; i++) {int st = 0, sf = 0;for (int j = 0; j < m; j++)if (i >> j & 1) {st += tt[j + 1], sf += s[j + 1];}3 行未改动int rt = r - ans;sort(tt + 1, tt + n + 1);int count = 0;for (int i = 1; i <= n; i++) {if (rt >= t[i]) {count++; rt -= t[i];}else break;}cout << count << endl;return 0;4 行未改动```cpp#include <bits/stdc++.h>#define ll long longusing namespace std;int n, ans = 1e9;int a[1000007], b[1000007];int read() {int r = 0, f = 1; char c = getchar();while ((c < '0' || c > '9') && (c ^ '-')) c = getchar();11 行未改动if (i >> j & 1) x *= a[j + 1], y += b[j + 1];if (x == 1 && y == 0) continue;ans = min(ans, abs(x - y));}cout << ans;return 0;}```14 行未改动15161718192021222357 行未改动8182838485868788899091929394959697989910010110210310410557 行未改动16316416516616716816917017117217317417517613 行未改动19019119219319419519619719819920020112 行未改动2142152162172182192202212223 行未改动2262272282292302312322332344 行未改动23924024124224324424524624711 行未改动25926026126226326426526626714 行未改动你希望计划成功率最大。因此,你需要选出合适的人士,来参与到你的宏图伟业中。## 输入格式第一行,两个正整数 $n, k$。分别表示供你挑选的人的数量,以及能力的种类数。接下来 $n$ 行,每行表示每个人拥有的能力。这一行首先有一个整数 $c$,表示该人士拥有多少种能力;接下来是 $c$ 个 $[1, k]$ 之间的正整数,表示该人士拥有哪些能力。## 输出格式57 行未改动### 输入 #4```21 60003 60 27 4801 482 52 142 4 31002 28 432 6 3101 73 45 6 4801 5102 28 202 37 511 853 59 39 29 23 53 27 13 16 44 34 38 24 9 32 58 54 31 1 7 45 3 30 36 17 48 42 22 18 21 6 11 25 33 37 52 10 60 49 57 2 28 8 14 5 47 4 41 35 43 50 46 26 1257 行未改动using namespace std;int n, k;long long a[50], s, u, ans;int main() {cin >> n >> k;for (int i = 1; i <= n; i++) {long long c, x; cin >> c;while(c--) cin >> x, a[i] |= long(pow(2, k - x));}long long len = 1 << n;for (int i = 0; i < len; i++) {long long sum = 0;for (int j = 0; j < n; j++)if (i >> j & 1) sum ^= a[j + 1];13 行未改动int h[1000007];int main() {cin >> n >> b;for (int i = 1; i <= n; i++) cin >> h[i];int len = 1 << n;for (int i = 0; i < len; i++) {int s = 0;for (int j = 0; j < n; j++)if (i >> j & 1) s += h[j + 1];if (s >= b) ans = min(ans, s - b);}cout << ans << endl;12 行未改动cin >> n >> m >> k >> r;for (int i = 1; i <= n; i++) cin >> t[i];for (int i = 1; i <= m; i++) cin >> tt[i];for (int i = 1; i <= m; i++) cin >> s[i];int len = 1 << m;for (int i = 0; i < len; i++) {int st = 0, sf = 0;for (int j = 0; j < m; j++)if (i >> j & 1) {st += tt[j + 1], sf += s[j + 1];}3 行未改动int rt = r - ans;sort(tt + 1, tt + n + 1);int count = 0;for (int i = 1; i <= n; i++) {if (rt >= t[i]) {count++; rt -= t[i];}else break;}cout << count << endl;return 0;4 行未改动```cpp#include <bits/stdc++.h>#define ll long longusing namespace std;int n, ans = 1e9;int a[1000007], b[1000007];int read() {int r = 0, f = 1; char c = getchar();while ((c < '0' || c > '9') && (c ^ '-')) c = getchar();11 行未改动if (i >> j & 1) x *= a[j + 1], y += b[j + 1];if (x == 1 && y == 0) continue;ans = min(ans, abs(x - y));}cout << ans;return 0;}```