QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#701906 | #7706. Rikka with Linker | TheZone | AC ✓ | 1012ms | 6712kb | C++17 | 812b | 2024-11-02 14:53:56 | 2024-11-02 14:54:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
const int N=19;
int f[1<<N|5];
int g[N],h[1<<N|5];
void solve() {
int n,m;
cin >> n >> m;
FOR(i,0,n-1) g[i]=0;
FOR(i,1,m) {
int x,y;
cin >> x >> y;
--x,--y;
g[x]|=1<<y;
}
FOR(i,0,(1<<n)-1) f[i]=1e9;
f[0]=0;
FOR(i,0,(1<<n)-1) {
FOR(j,0,n-1) h[1<<j]=1;
FOR(j,0,n-1) if((1<<j)&i) {
h[g[j]^(g[j]&i)]++;
}
FOR(j,0,n-1) if(!((1<<j)&i)) {
f[i|(1<<j)]=min(f[i|(1<<j)],h[1<<j]+f[i]);
}
}
cout << f[(1<<n)-1] << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while(T--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5660kb
input:
3 3 2 1 2 2 3 3 3 1 2 2 3 3 1 5 7 1 2 2 3 3 5 5 4 4 2 2 5 3 1
output:
3 4 6
result:
ok 3 number(s): "3 4 6"
Test #2:
score: 0
Accepted
time: 1012ms
memory: 6712kb
input:
1000 18 93 1 6 1 13 2 1 2 8 3 6 4 8 5 4 5 6 5 9 5 10 5 11 5 12 5 13 5 18 6 2 6 4 6 16 7 1 7 2 7 3 7 9 7 10 7 13 7 15 8 6 8 9 9 5 9 8 9 10 9 13 9 14 10 1 10 3 10 4 10 5 10 6 10 8 10 11 10 13 11 1 11 2 11 3 11 4 11 6 11 7 11 9 11 12 11 14 11 15 12 1 12 2 12 4 12 6 12 10 12 13 12 14 12 16 12 17 12 18 1...
output:
23 24 25 25 26 28 26 28 28 27 28 29 27 27 29 28 31 31 30 31 19 17 18 17 19 13 19 18 18 19 20 15 19 15 19 20 18 19 20 15 18 19 18 17 18 17 19 18 18 19 21 20 18 13 14 15 19 17 18 18 20 19 19 20 19 17 20 19 19 16 18 16 18 18 18 19 17 15 20 19 18 20 18 19 18 19 18 19 18 14 18 19 17 20 18 19 19 19 19 19 ...
result:
ok 1000 numbers