QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#696427#7662. Kaldorian KnightshowdionRE 1ms3736kbC++171.3kb2024-10-31 22:33:242024-10-31 22:33:25

Judging History

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

  • [2024-10-31 22:33:25]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3736kb
  • [2024-10-31 22:33:24]
  • 提交

answer

#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <string.h>
#include <iomanip>
#include <unordered_set>

#define int long long

using namespace std;

const int N = 5e3 + 9;
const int mod = 1e9 + 7;

int n, h;
int k[N];
int s[N];
int f[N];
int dp[N];

void setup()
{
	f[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		f[i] = (f[i - 1] * i) % mod;
	}
}

int solve()
{
	if (s[h] == n) return 0;
	setup();
	if (h == 0) return f[n];

	dp[h] = (f[n - s[h - 1]]  + mod - (f[k[h]] * f[n - s[h]]) % mod) % mod;
	for (int i = h - 1; i >= 1; i--)
	{
		int currS = s[h] - s[i - 1];
		int currN = n - s[i - 1];
		dp[i] = (f[currN]  + mod - (f[currS] * f[currN - currS]) % mod) % mod;
		for (int j = h - 1; j >= i; j--)
		{
			dp[i] = (dp[i] + mod - (f[currS - s[h] + s[j]] * dp[j + 1]) % mod) % mod;
		}
	}
	return dp[1];
}

signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
	if (fopen("data.inp", "r")) 	
	{
		freopen ("data.inp", "r", stdin);
		freopen ("data.out", "w", stdout);
	}
	cin >> n >> h;
	for (int i = 1; i <= h; i++)
	{
		cin >> k[i];
		s[i] = s[i - 1] + k[i];
	}
	cout << solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 0

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

4 1
3

output:

18

result:

ok single line: '18'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3724kb

input:

4 2
2
1

output:

16

result:

ok single line: '16'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3716kb

input:

10 1
10

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

10 10
1
1
1
1
1
1
1
1
1
1

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

1357 7
56
173
21
103
96
149
38

output:

1000000006

result:

ok single line: '1000000006'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

1357 5
190
198
257
256
261

output:

1000000005

result:

ok single line: '1000000005'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

1357 7
144
56
113
20
113
141
107

output:

0

result:

ok single line: '0'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

1357 7
107
29
131
99
180
96
63

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

1357 7
124
180
60
103
142
145
68

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

750 66
7
2
2
1
7
10
9
10
5
9
10
11
11
5
4
3
8
6
5
5
6
9
5
1
7
11
8
5
4
6
4
2
7
2
9
11
4
8
10
8
6
2
8
7
11
3
10
9
4
3
7
5
5
9
6
2
10
7
5
2
5
4
9
3
11
9

output:

685840434

result:

ok single line: '685840434'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

750 66
6
1
3
6
6
2
11
7
4
4
7
5
4
9
7
2
2
6
7
10
6
3
5
4
6
5
6
5
3
10
7
9
6
5
11
1
1
9
4
6
7
3
3
4
7
11
4
5
1
8
7
10
9
10
2
6
6
5
8
8
4
4
11
5
3
8

output:

148626971

result:

ok single line: '148626971'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

750 66
3
5
3
11
11
9
9
4
7
8
3
4
4
5
11
9
1
6
9
6
7
8
11
7
9
7
1
10
3
8
10
6
3
4
8
11
9
6
1
11
1
8
7
7
2
9
5
5
6
1
8
10
10
9
5
11
3
9
10
6
1
6
3
8
8
3

output:

817964272

result:

ok single line: '817964272'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

750 66
2
8
1
1
7
11
4
8
5
6
3
11
11
5
3
2
1
6
3
6
6
5
2
8
11
6
6
7
8
1
5
11
6
8
2
3
7
10
10
6
6
11
7
5
6
6
5
9
7
3
4
4
10
4
6
4
3
9
6
6
11
2
4
6
6
11

output:

936531345

result:

ok single line: '936531345'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3688kb

input:

750 66
4
6
11
1
6
9
7
1
5
4
5
6
2
8
1
2
11
6
5
3
1
6
9
8
5
9
6
2
5
1
5
3
8
6
8
5
7
4
8
1
11
11
10
8
4
6
5
10
7
8
8
8
3
9
1
8
2
9
7
5
3
1
1
11
7
4

output:

484040613

result:

ok single line: '484040613'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3732kb

input:

750 66
4
9
10
7
10
11
3
7
1
6
11
4
2
11
5
5
1
2
9
7
8
3
5
8
5
6
11
6
1
11
8
8
9
6
6
9
9
7
11
11
3
7
8
10
8
9
9
5
8
8
9
7
7
11
8
6
1
10
1
11
11
11
3
5
11
8

output:

205283749

result:

ok single line: '205283749'

Test #17:

score: -100
Runtime Error

input:

10000 135
51
12
73
56
26
59
61
62
19
65
54
35
64
74
73
49
62
57
51
35
22
62
26
19
50
36
24
54
41
74
26
58
45
40
6
24
55
39
10
47
70
15
61
31
54
2
48
56
2
10
1
25
24
39
70
63
10
73
15
73
51
59
28
58
28
59
24
2
72
33
30
21
63
5
38
60
26
16
57
15
58
47
17
8
32
13
36
10
14
46
4
16
68
71
56
58
58
36
52
1...

output:


result: