UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203963#3572. 排列数数drdilyor1001622ms33964kbC++496b2024-03-31 09:06:432024-03-31 12:00:25

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
int dp[(1<<22)+5];
const int mod=1e9+7;
int cond[22];
signed main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--,v--;
		cond[v]|=(1<<u);
	}
	dp[0]=1;
	for(int i=1;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				if(((i^(1<<j))&cond[j])!=cond[j])continue;
				dp[i]+=dp[i^(1<<j)];
				if(dp[i]>=mod)dp[i]-=mod;
			}
		}
	}
	cout<<dp[(1<<n)-1]<<"\n";
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1204kb

input:

10 20
2 6
1 7
1 8
4 7
8 7
4 7
7 5
3 5
3 1
6 7
2 10
10 5
9 8
8 6
8 7
6 10
7 5
3 10
4 10
8 7

output:

210

result:

ok single line: '210'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1208kb

input:

10 50
8 7
9 7
9 6
9 10
7 5
6 2
3 1
8 5
2 5
9 10
6 2
4 7
8 5
7 2
10 7
9 8
9 7
3 2
6 2
1 4
8 4
7 2
9 5...

output:

9

result:

ok single line: '9'

Test #3:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

9 3
6 7
6 5
9 1

output:

60480

result:

ok single line: '60480'

Test #4:

score: 10
Accepted
time: 0ms
memory: 1204kb

input:

10 400
7 6
4 2
6 3
6 3
4 2
1 8
10 4
1 10
10 6
4 2
10 9
10 8
10 4
5 4
1 2
9 3
5 4
4 6
10 3
10 2
8 4
9...

output:

1

result:

ok single line: '1'

Test #5:

score: 10
Accepted
time: 0ms
memory: 1204kb

input:

10 10
2 9
5 10
4 10
9 8
3 6
1 2
5 3
3 2
3 8
3 6

output:

4470

result:

ok single line: '4470'

Test #6:

score: 10
Accepted
time: 338ms
memory: 33964kb

input:

22 3
6 11
1 12
17 8

output:

700330084

result:

ok single line: '700330084'

Test #7:

score: 10
Accepted
time: 299ms
memory: 33964kb

input:

22 372
11 2
11 4
15 9
21 19
21 12
19 6
9 8
21 20
4 10
5 11
5 4
6 10
20 6
22 5
3 20
1 9
3 19
11 6
16 ...

output:

108

result:

ok single line: '108'

Test #8:

score: 10
Accepted
time: 370ms
memory: 33960kb

input:

22 40
13 17
8 2
15 1
8 18
19 13
16 20
16 15
5 6
21 14
21 13
11 3
5 8
10 9
11 1
8 17
12 21
11 4
1 21
...

output:

291292779

result:

ok single line: '291292779'

Test #9:

score: 10
Accepted
time: 280ms
memory: 33964kb

input:

22 100
1 22
13 15
1 9
14 16
12 21
6 2
4 15
2 15
10 15
20 6
6 5
8 3
2 15
16 15
9 21
11 2
8 15
13 16
1...

output:

13220416

result:

ok single line: '13220416'

Test #10:

score: 10
Accepted
time: 335ms
memory: 33964kb

input:

22 30
4 16
1 16
18 1
3 2
5 10
21 16
4 16
11 8
8 7
20 21
19 7
6 21
19 7
1 19
5 19
21 11
10 11
10 8
19...

output:

231868313

result:

ok single line: '231868313'

Extra Test:

score: 0
Extra Test Passed