#include <iostream> #include <bitset> #include <unordered_set> const int MAX = 1000+5; const int MAXB = 36; const int MOD = 2; int A[MAX]; int B[MAX]; int n,m; int NN[MAXB][MAXB]; int NS[MAXB]; int solve(int k) { std::bitset<MAXB> b; for (int i=1;i<=k;++i) b[i] = true; std::unordered_set<uint64_t> Q,G; Q.insert(b.to_ullong()); for (int i=k+1;i<=n;++i) { b[i] = true; b[i-k] = false; Q.insert(b.to_ullong()); } // std::clog << " :: " << k << std::endl; for (int i=m-1;i>=0;--i) { // std::clog << " :: :: " << i << " :: " << A[i] << " -> " << B[i] << std::endl; // for (auto bb : Q) std::clog << " :: " << std::bitset<MAXB>(bb) << std::endl; for (auto bb : Q) { b = std::bitset<MAXB>(bb); if (!b[A[i]] && !b[B[i]]) G.insert(b.to_ullong()); else if (b[A[i]] && b[B[i]]) G.insert(b.to_ullong()); else if (!b[A[i]] && b[B[i]]) { G.insert(b.to_ullong()); b[A[i]] = true; b[B[i]] = false; G.insert(b.to_ullong()); } } std::swap(G,Q); G.clear(); } // for (auto bb : Q) std::clog << " :: " << std::bitset<MAXB>(bb) << std::endl; return Q.size() % MOD; } void init() { NS[0]=1; for (int i=1;i<=n;++i) NS[i] = NS[i-1]*i%MOD; for (int i=0;i<=n;++i) NN[i][i] = NN[i][0] = 1; for (int i=1;i<=n;++i) for (int j=1;j<i;++j) NN[i][j] = (NN[i-1][j-1] + NN[i-1][j] ) % MOD; } int main() { std::ios_base::sync_with_stdio(0); std::cin >> n >> m; init(); for (int i=0;i<m;++i) std::cin >> A[i] >> B[i]; // for (int i=1;i<=n;++i) std::cout << (i==1 ? "" : " ") << solve(i); for (int i=1;i<=n;++i) std::cout << solve(i) << " "; std::cout << std::endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include <iostream> #include <bitset> #include <unordered_set> const int MAX = 1000+5; const int MAXB = 36; const int MOD = 2; int A[MAX]; int B[MAX]; int n,m; int NN[MAXB][MAXB]; int NS[MAXB]; int solve(int k) { std::bitset<MAXB> b; for (int i=1;i<=k;++i) b[i] = true; std::unordered_set<uint64_t> Q,G; Q.insert(b.to_ullong()); for (int i=k+1;i<=n;++i) { b[i] = true; b[i-k] = false; Q.insert(b.to_ullong()); } // std::clog << " :: " << k << std::endl; for (int i=m-1;i>=0;--i) { // std::clog << " :: :: " << i << " :: " << A[i] << " -> " << B[i] << std::endl; // for (auto bb : Q) std::clog << " :: " << std::bitset<MAXB>(bb) << std::endl; for (auto bb : Q) { b = std::bitset<MAXB>(bb); if (!b[A[i]] && !b[B[i]]) G.insert(b.to_ullong()); else if (b[A[i]] && b[B[i]]) G.insert(b.to_ullong()); else if (!b[A[i]] && b[B[i]]) { G.insert(b.to_ullong()); b[A[i]] = true; b[B[i]] = false; G.insert(b.to_ullong()); } } std::swap(G,Q); G.clear(); } // for (auto bb : Q) std::clog << " :: " << std::bitset<MAXB>(bb) << std::endl; return Q.size() % MOD; } void init() { NS[0]=1; for (int i=1;i<=n;++i) NS[i] = NS[i-1]*i%MOD; for (int i=0;i<=n;++i) NN[i][i] = NN[i][0] = 1; for (int i=1;i<=n;++i) for (int j=1;j<i;++j) NN[i][j] = (NN[i-1][j-1] + NN[i-1][j] ) % MOD; } int main() { std::ios_base::sync_with_stdio(0); std::cin >> n >> m; init(); for (int i=0;i<m;++i) std::cin >> A[i] >> B[i]; // for (int i=1;i<=n;++i) std::cout << (i==1 ? "" : " ") << solve(i); for (int i=1;i<=n;++i) std::cout << solve(i) << " "; std::cout << std::endl; return 0; } |