QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#232864 | #6410. Classical DP Problem | bianca | WA | 0ms | 3716kb | C++14 | 1.3kb | 2023-10-30 23:50:39 | 2023-10-30 23:50:39 |
Judging History
answer
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
#define MaxN 5000
#define MOD 998244353
int a[MaxN], b[MaxN];
int dp[MaxN][MaxN];
int dinamic(int a[], int k, int x)
{
dp[0][x]=1;
int i, j;
for(i=0; i<k; i++)
{
for(j=x; j>=0; j--)
{
dp[i+1][j]+=(a[i+1]-j)*dp[i][j];
dp[i+1][j]%=MOD;
if(j>0)
{
dp[i+1][j-1]+=j*dp[i][j];
dp[i+1][j-1]%=MOD;
}
}
}
return dp[k][0];
}
int fact(int k)
{
int prod=1;
while(k>0)
{
prod=prod*k;
prod%=MOD;
k--;
}
return prod;
}
int main()
{
int n, i, j, k, x=0, res;
cin>>n;
for(i=1; i<=n; i++)
{
cin>>a[i];
}
k=1;
while(n-k>a[k])
{
k++;
}
cout<<k<<" ";
reverse(a+1, a+n+1);
x=a[k+1];
res+=dinamic(a, k, x);
for(i=n; i>0; i--)
{
j=1;
while(a[j]>=i)
{
j++;
}
b[i]=j-1;
}
x=b[k+1];
for(i=0; i<=n; i++)
{
for(j=0; j<=n; j++)
{
dp[i][j]=0;
}
}
res+=dinamic(b, k, x);
res%=MOD;
res-=fact(k);
cout<<res;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3716kb
input:
3 1 2 3
output:
2 6
result:
ok 2 number(s): "2 6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
2 1 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3588kb
input:
2 2 2
output:
1 -1
result:
wrong answer 1st numbers differ - expected: '2', found: '1'