QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#696420#7662. Kaldorian KnightshowdionWA 1ms3716kbC++171.3kb2024-10-31 22:31:322024-10-31 22:31:32

Judging History

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

  • [2024-10-31 22:31:32]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3716kb
  • [2024-10-31 22:31:32]
  • 提交

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 ll 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: 0ms
memory: 3716kb

input:

3 0

output:

6

result:

ok single line: '6'

Test #2:

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

input:

4 1
3

output:

18

result:

ok single line: '18'

Test #3:

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

input:

4 2
2
1

output:

16

result:

ok single line: '16'

Test #4:

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

input:

10 1
10

output:

0

result:

ok single line: '0'

Test #5:

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

input:

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

output:

0

result:

ok single line: '0'

Test #6:

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

input:

1357 7
56
173
21
103
96
149
38

output:

720983311

result:

wrong answer 1st lines differ - expected: '1000000006', found: '720983311'