QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232921#6410. Classical DP Problemiulia_morariuWA 0ms3848kbC++141.7kb2023-10-31 01:01:592023-10-31 01:02:00

Judging History

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

  • [2023-10-31 01:02:00]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3848kb
  • [2023-10-31 01:01:59]
  • 提交

answer

#include <bits/stdc++.h>
#define Mod 1000000007

using namespace std;

int k;
int din(vector <int> a){
    int n = a.size();
    int x = 0;
    int it = n - 1;
    if(n == k) x = 0;
    else x = a[k];

    int dp[n + 1][n + 1];
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++) dp[i][j] = 0;
    }

    dp[0][ x ] = 1;

    for(int i = 0; i < k; i++){
        for(int j = 0; j <= x; j++){
            // acoperim o cloana neimportanta
            dp[i + 1][j] += (a[i] - j) * dp[i][j];
            dp[i + 1][j] %= Mod;
            // acoperim o coloana importanta
            if(j > 0){
                dp[i + 1][j - 1] += j * dp[i][j];
                dp[i + 1][j - 1] %= Mod;
            }
        }
    }


    return dp[k][0];
}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);

    int n; cin >> n;
    vector <int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    reverse(v.begin(), v.end());
    k = n;

    for(int i = 0; i < n; i++){
        if(v[i] < i + 1){
            k = i;
            break;
        }
    }

    cout << k << " ";


    int val1 = din(v);
    //cout << "val1 = "  << val1 << endl;

    vector<int> v1(n);
    for(int i = 0; i < n; i++) v1[i] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < v[i]; j++){
            v1[j]++;
        }
    }
    //reverse(v1.begin(), v1.end());

    int val2 = din(v1);
    //cout << "val2 = " << val2 << endl;

    int fact = 1;
    for(int i = 2; i <= k; i++){
        fact *= i;
        fact %= Mod;
    }
    //cout << "fact = " << fact << endl;

    cout << val1 + val2 - fact << endl;



    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

input:

3
1 2 3

output:

2 6

result:

ok 2 number(s): "2 6"

Test #2:

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

input:

1
1

output:

1 1

result:

ok 2 number(s): "1 1"

Test #3:

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

input:

2
1 1

output:

1 2

result:

ok 2 number(s): "1 2"

Test #4:

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

input:

2
2 2

output:

2 6

result:

ok 2 number(s): "2 6"

Test #5:

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

input:

3
1 1 1

output:

1 3

result:

ok 2 number(s): "1 3"

Test #6:

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

input:

3
2 2 2

output:

2 9

result:

ok 2 number(s): "2 9"

Test #7:

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

input:

3
3 3 3

output:

3 48

result:

ok 2 number(s): "3 48"

Test #8:

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

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: 3544kb

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: 3776kb

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 -912654116

result:

wrong answer 2nd numbers differ - expected: '986189864', found: '-912654116'