QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#791313#7925. ChayasPoonYaPatWA 1ms7712kbC++14982b2024-11-28 18:02:162024-11-28 18:02:18

Judging History

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

  • [2024-11-28 18:02:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7712kb
  • [2024-11-28 18:02:16]
  • 提交

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,com[MX],val[27][27];
ll dp[MX];
bool can[MX][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[a][b]|=(1<<c);
        val[c][b]|=(1<<c);
    }
    int mul=1;
    for (int i=0; i<n; ++i) com[mul]=i, mul*=2;

    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[com[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";
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7712kb

input:

5 4
1 2 4
2 3 5
3 2 4
1 3 2

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 1ms
memory: 7648kb

input:

4 2
3 1 4
1 4 3

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 1ms
memory: 7668kb

input:

5 5
3 1 2
2 5 4
5 4 3
3 1 5
1 4 5

output:

2

result:

ok single line: '2'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 7676kb

input:

6 6
1 6 3
2 3 4
5 6 4
3 5 1
1 3 4
1 2 4

output:

24

result:

wrong answer 1st lines differ - expected: '6', found: '24'