Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
- #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
- #define cout_map(mp) for(auto& [f, s] : mp) cout << f << " " << s << "\n";
- #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
- #define fixed(n) fixed << setprecision(n)
- #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
- #define fill(vec, value) memset(vec, value, sizeof(vec));
- #define Num_of_Digits(n) ((int)log10(n) + 1)
- #define mod_combine(a, b, m) (((a % m) * (b % m)) % m)
- #define all(vec) vec.begin(), vec.end()
- #define rall(vec) vec.rbegin(), vec.rend()
- #define sz(x) int(x.size())
- #define debug(x) cout << #x << ": " << (x) << "\n";
- #define fi first
- #define se second
- #define ll long long
- #define ull unsigned long long
- #define Mod 1'000'000'007
- #define OO 2'000'000'000
- #define EPS 1e-9
- #define PI acos(-1)
- template < typename T = int > using Pair = pair < T, T >;
- template < typename T = int > istream& operator >> (istream &in, vector < T > &v) {
- for (auto &x: v) in >> x;
- return in;
- }
- template < typename T = int > ostream& operator << (ostream &out, const vector < T > &v) {
- for (const T &x: v) out << x << ' ';
- return out;
- }
- template < int MOD = 1000000007 > struct ModInt {
- int val;
- ModInt(int V = 0) : val(V) { val %= MOD; }
- ModInt& operator += (const ModInt& rhs) {
- if ((val += rhs.val) >= MOD) val -= MOD;
- return *this;
- }
- ModInt& operator += (const int rhs) {
- if ((val += rhs) >= MOD) val -= MOD;
- return *this;
- }
- ModInt& operator -= (const ModInt& rhs) {
- if ((val += MOD - rhs.val) >= MOD) val -= MOD;
- return *this;
- }
- ModInt& operator -= (const int rhs) {
- if ((val += MOD - rhs) >= MOD) val -= MOD;
- return *this;
- }
- ModInt& operator *= (const ModInt& rhs) { val = (1ll * val * rhs.val) % MOD; return *this; }
- ModInt& operator *= (const int rhs) { val = (1ll * val * rhs) % MOD; return *this; }
- ModInt& operator /= (const ModInt& rhs) { return *this *= rhs.inverse(); }
- ModInt& operator /= (const int rhs) { return *this *= ModInt(rhs).inverse(); }
- ModInt& operator %= (const ModInt& rhs) { val %= rhs.val; return *this; }
- ModInt& operator %= (const int rhs) { val %= rhs; return *this; }
- ModInt& operator ++() { return *this += 1; }
- ModInt& operator --() { return *this -= 1; }
- ModInt operator ++(int unused) { ModInt res(*this); ++*this; return res; }
- ModInt operator --(int unused) { ModInt res(*this); --*this; return res; }
- ModInt operator + (const ModInt& rhs) const { ModInt res(*this); return res += rhs; }
- ModInt operator + (const int rhs) const { ModInt res(*this); return res += rhs; }
- ModInt operator % (const ModInt& rhs) const { ModInt res(*this); return res %= rhs; }
- ModInt operator % (const int rhs) const { ModInt res(*this); return res %= rhs; }
- ModInt operator - (const ModInt& rhs) const { ModInt res(*this); return res -= rhs; }
- ModInt operator - (const int rhs) const { ModInt res(*this); return res -= rhs; }
- ModInt operator * (const ModInt& rhs) const { ModInt res(*this); return res *= rhs; }
- ModInt operator * (const int rhs) const { ModInt res(*this); return res *= rhs; }
- ModInt operator / (const ModInt& rhs) const { ModInt res(*this); return res /= rhs; }
- ModInt operator / (const int rhs) const { ModInt res(*this); return res /= rhs; }
- ModInt& operator = (const ModInt& rhs) { val = rhs.val; return *this; }
- ModInt& operator = (const int rhs) { val = rhs; return *this; }
- bool operator == (const ModInt& rhs) const { return val == rhs.val; }
- bool operator == (const int rhs) const { return val == rhs; }
- bool operator != (const ModInt& rhs) const { return val != rhs.val; }
- bool operator != (const int rhs) const { return val != rhs; }
- bool operator < (const ModInt& rhs) const { return val < rhs.val; }
- bool operator < (const int rhs) const { return val < rhs; }
- bool operator <= (const ModInt& rhs) const { return val <= rhs.val; }
- bool operator <= (const int rhs) const { return val <= rhs; }
- bool operator > (const ModInt& rhs) const { return val > rhs.val; }
- bool operator > (const int rhs) const { return val > rhs; }
- bool operator >= (const ModInt& rhs) const { return val >= rhs.val; }
- bool operator >= (const int rhs) const { return val >= rhs; }
- int operator () () const { return val; }
- ModInt inverse() const { return power(MOD - 2); }
- ModInt power(ll n) const {
- ModInt a = *this, res = 1;
- while (n > 0) {
- if (n & 1) res *= a;
- a *= a, n >>= 1;
- }
- return res;
- }
- ModInt power(ModInt n) const {
- ModInt a = *this, res = 1;
- int e = n();
- while (e > 0) {
- if (e & 1) res *= a;
- a *= a, e >>= 1;
- }
- return res;
- }
- friend ModInt operator ^ (ModInt rhs, ll n) { return rhs.power(n); }
- friend ModInt operator ^ (ModInt rhs, ModInt n) { return rhs.power(n); }
- friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
- friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
- };
- using Mint = ModInt < >;
- constexpr int N = 20;
- vector < vector < int > > adj(N + 5);
- vector < Mint > dp(1 << N, -1);
- int n;
- Mint cnt_ways(int u, int mask){
- if(u == n) return 1;
- Mint& ret = dp[mask];
- if(ret != -1) return ret;
- ret = 0;
- for(auto& v : adj[u])
- if(!(mask & (1 << v)))
- ret += cnt_ways(u + 1, mask | (1 << v));
- return ret;
- }
- void Solve(){
- cin >> n;
- for(int i = 0; i < n; i++)
- for(int j = 0, val; j < n && cin >> val; j++)
- if(val == 1)
- adj[i].push_back(j);
- cout << cnt_ways(0, 0) << "\n";
- }
- int main(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int t = 1;
- //cin >> t;
- while(t--)
- Solve();
- return 0;
- }
Add Comment
Please, Sign In to add comment