Submission #441144

#TimeUsernameProblemLanguageResultExecution timeMemory
441144AutronAmusement Park (CEOI19_amusementpark)C++14
100 / 100
2157 ms308884 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define MOD 998244353 int adj[20]; map<int, int> dp[1<<18]; int32_t main(){ int n, m; cin>>n>>m; for(int i=1;i<=m;++i){ int a, b; cin>>a>>b; a--, b--; adj[a]|=(1<<b); adj[b]|=(1<<a); } dp[0][(1<<n)-1]=1; for(int mask=0;mask<(1<<n);++mask){ for(auto it:dp[mask]){ int mask2=it.first; int nr=it.second; for(int x=0;x<n;++x){ if(mask2&(1<<x)){ int aux=mask2; aux=aux&(((1<<n)-1)-((1<<(x+1))-1)); aux=aux|((adj[x]|mask)^mask); dp[mask|(1<<x)][aux]+=nr; dp[mask|(1<<x)][aux]%=MOD; } } } } int sol=dp[(1<<n)-1][0]; sol=(sol*m)%MOD; sol=(sol*(MOD+1)/2)%MOD; cout<<sol<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...