QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#232835 | #6410. Classical DP Problem | Laurra | WA | 1ms | 5404kb | C++14 | 1.5kb | 2023-10-30 23:29:09 | 2023-10-30 23:29:10 |
Judging History
answer
#include <iostream>
#include <vector>
using namespace std;
#define MOD 998244353
#define dim 5002
#define ll long long
vector<int> v;
int n;
bool ok(int i,int j)
{
if(i>=1 && v[i]>=j)
return true;
return false;
}
int dp[dim][dim];
ll fact(int k)
{
ll p=1,i;
for(i=2;i<=k;i++)
p*=i;
return p;
}
void init()
{
int i,j;
for(i=0;i<=n;i++)
{
for(j=0;j<=n;j++)
dp[i][j]=0;
}
}
ll calc(int k)
{
int x=v[k+1],i,j;
dp[0][x]=1;
for(i=0;i<k;i++)
{
for(j=0;j<=x;j++)
{
if(j)
{
dp[i+1][j-1]=(dp[i+1][j-1]+(j*dp[i][j])%MOD)%MOD;
}
dp[i+1][j]=(dp[i+1][j]+((v[i+1]-j)*dp[i][j])%MOD)%MOD;
}
}
return dp[k][0]%MOD;
}
void flip()
{
vector<int> v2(n+1);
int i,j;
for(i=1;i<=n;i++)
{
j=1;
while(j<=n && v[j]>=i)
j++;
v2[i]=j-1;
}
v=v2;
}
int main()
{
int k,j,i;
ll tot=0;
//Citire
cin>>n;
v.resize(n+1);
for(i=1;i<=n;i++)
{
cin>>v[n-i+1];
}
//Calc nr ture
k=0;
j=1;
i=1;
while(ok(i,j)==true)
{
i++;
j++;
k++;
}
cout<<k<<" ";
//Dinamica
init();
tot+=calc(k);
flip();
init();
tot%=MOD;
tot+=calc(k);
tot-=fact(k);
while(tot<0)
tot+=MOD;
tot%=MOD;
cout<<tot;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3448kb
input:
3 1 2 3
output:
2 6
result:
ok 2 number(s): "2 6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3376kb
input:
1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5404kb
input:
2 1 1
output:
1 2
result:
ok 2 number(s): "1 2"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3380kb
input:
2 2 2
output:
2 6
result:
ok 2 number(s): "2 6"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3400kb
input:
3 1 1 1
output:
1 3
result:
ok 2 number(s): "1 3"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
3 2 2 2
output:
2 9
result:
ok 2 number(s): "2 9"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3400kb
input:
3 3 3 3
output:
3 48
result:
ok 2 number(s): "3 48"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
5 1 1 3 3 4
output:
3 47
result:
ok 2 number(s): "3 47"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
10 2 4 5 5 5 5 6 8 8 10
output:
5 864
result:
ok 2 number(s): "5 864"
Test #10:
score: -100
Wrong Answer
time: 0ms
memory: 3552kb
input:
30 6 8 9 9 9 10 13 14 15 15 16 17 17 18 20 22 22 23 23 24 24 25 25 25 27 28 28 29 29 30
output:
17 793952967
result:
wrong answer 2nd numbers differ - expected: '986189864', found: '793952967'