QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#791295#7925. ChayasPoonYaPatML 0ms0kbC++14987b2024-11-28 17:55:482024-11-28 17:55:49

Judging History

你现在查看的是最新测评结果

  • [2024-11-28 17:55:49]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2024-11-28 17:55:48]
  • 提交

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

result: