QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#232843 | #6410. Classical DP Problem | elisaipate | WA | 0ms | 5688kb | C++14 | 1.0kb | 2023-10-30 23:36:24 | 2023-10-30 23:36:25 |
Judging History
answer
#include <iostream>
using namespace std;
#define nmax 5001
#define mod 998244353
int lin[nmax], col[nmax];
long long dp[2][nmax][nmax], n, k;
void fctdp( int ind, int a[] ) {
int i, j;
for( i = 0; i < k; i++ ) {
for( j = 0; j < k; j++ ) {
dp[ind][i+1][j] += (a[i+1] - j) * dp[ind][i][j] % mod;
if( j >= 1 )
dp[ind][i+1][j-1] += j*dp[ind][i][j] % mod;
}
}
}
int main()
{
int i, nr;
long long fact;
cin >> n;
for( i = n; i >= 1; i-- )
cin >> lin[i];
nr = n;
for( i = 1; i <= n; i++) {
while( lin[nr] < i )
nr--;
col[i] = nr;
}
k = 1;
while( lin[k] >= k )
k++;
k--;
dp[0][0][lin[k+1]] = 1;
dp[1][0][col[k+1]] = 1;
fctdp( 0, lin );
fctdp( 1, col );
fact = 1;
for( i = 2; i <= k; i++ )
fact = fact * i % mod;
cout << dp[0][k][0] + dp[1][k][0] - fact;
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5688kb
input:
3 1 2 3
output:
6
result:
wrong answer 1st numbers differ - expected: '2', found: '6'