kyopro-lib

This documentation is automatically generated by online-judge-tools/verification-helper

View on GitHub

:warning: Count topological sort
(Mylib/Graph/TopologicalSort/count_topological_sort.cpp)

Operations

Requirements

Notes

Problems

References

Code

#pragma once
#include <cstdint>
#include <vector>

namespace haar_lib {
  int64_t count_topological_sort(const std::vector<int> &g) {
    const int n = g.size();
    std::vector<int64_t> dp(1 << n);

    dp[0] = 1;

    for (int s = 0; s < (1 << n); ++s) {
      for (int i = 0; i < n; ++i) {
        if (s & (1 << i)) {
          if ((s ^ (1 << i)) & g[i]) continue;
          dp[s] += dp[s ^ (1 << i)];
        }
      }
    }

    return dp[(1 << n) - 1];
  }
}  // namespace haar_lib
#line 2 "Mylib/Graph/TopologicalSort/count_topological_sort.cpp"
#include <cstdint>
#include <vector>

namespace haar_lib {
  int64_t count_topological_sort(const std::vector<int> &g) {
    const int n = g.size();
    std::vector<int64_t> dp(1 << n);

    dp[0] = 1;

    for (int s = 0; s < (1 << n); ++s) {
      for (int i = 0; i < n; ++i) {
        if (s & (1 << i)) {
          if ((s ^ (1 << i)) & g[i]) continue;
          dp[s] += dp[s ^ (1 << i)];
        }
      }
    }

    return dp[(1 << n) - 1];
  }
}  // namespace haar_lib
Back to top page