teamnote default

This commit is contained in:
2026-06-03 09:20:51 +09:00
commit f50ed902fe
65 changed files with 6033 additions and 0 deletions

22
source/DP/SoS.cpp Normal file
View File

@@ -0,0 +1,22 @@
int n = 20;
vector<int> a(1 << n);
// keeps track of the sum over subsets
// with a certain amount of matching bits in the prefix
vector<vector<int>> dp(1 << n, vector<int>(n));
vector<int> sos(1 << n);
for (int mask = 0; mask < (1 << n); mask++) {
dp[mask][-1] = a[mask];
for (int x = 0; x < n; x++) {
dp[mask][x] = dp[mask][x - 1];
if (mask & (1 << x)) { dp[mask][x] += dp[mask - (1 << x)][x - 1]; }
}
sos[mask] = dp[mask][n - 1];
}
////////////////////////////////////////////
D[i] i에
fors(d, 0, 19) fors(i,0,(1<<20)-1)
if(i & (1<<d)) D[i] += D[i^(1<<d)];
-> D[i] : sum of subset of mask i