QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#791295 | #7925. Chayas | PoonYaPat | ML | 0ms | 0kb | C++14 | 987b | 2024-11-28 17:55:48 | 2024-11-28 17:55:49 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod= 998244353;
const int MX=(1<<24)+10;
int n,m;
vector<ll> dp(MX);
vector<vector<bool>> can(MX, vector<bool>(25));
vector<vector<int>> val(MX, vector<int>(25));
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
for (int i=0; i<m; ++i) {
int a,b,c; cin>>a>>b>>c;
--a; --b; --c;
val[(1<<a)][b]|=(1<<c);
val[(1<<c)][b]|=(1<<c);
}
for (int k=0; k<n; ++k) {
can[0][k]=true;
for (int bit=1; bit<(1<<n); ++bit) {
int x=bit&-bit,lft=bit-x;
if (can[lft][k] && ((val[x][k]&lft)==0)) can[bit][k]=true;
}
}
dp[0]=1;
for (int bit=1; bit<(1<<n); ++bit) {
for (int k=0; k<n; ++k) if (bit&(1<<k)) {
if (can[bit^(1<<k)][k] && can[bit^((1<<n)-1)][k]) dp[bit]=(dp[bit]+dp[bit^(1<<k)])%mod;
}
}
cout<<dp[(1<<n)-1]<<"\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
5 4 1 2 4 2 3 5 3 2 4 1 3 2
output:
4