QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#86602#4807. Melborp Lacissalccodicon#AC ✓688ms38220kbC++232.1kb2023-03-10 11:58:392023-03-10 11:58:41

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-10 11:58:41]
  • 评测
  • 测评结果:AC
  • 用时:688ms
  • 内存:38220kb
  • [2023-03-10 11:58:39]
  • 提交

answer

//
// Created by codicon on 3/9/2023 at 6:56 PM.
//

// O(n^5/2^2)

// The idea is that there is a bijection between the n + 1prefix sums and the n values of the array

#include <bits/stdc++.h>

using namespace std;

# define add(a, b) a = ((a) + (b)) % MOD;

int n, k, t;

const int MAXN = 64, MOD =  998'244'353;

int dp[MAXN + 1][MAXN + 2][(MAXN)*(MAXN+1)/2 + 1];

long long FAC[MAXN+2], INV_FAC[MAXN+2];
long long ch[MAXN+1][MAXN+1];

long long binexp(long long b, int e) {
    long long res = 1;

    for (; e; b = b * b % MOD, e >>= 1) {
        if (e&1) res = res * b % MOD;
    }

    return res;
}

long long choose(int n, int k) {
    if (k > n) {
        return 0;
    }

    return (FAC[n] * INV_FAC[k] % MOD) * INV_FAC[n-k] % MOD;
}

void set_up() {
    FAC[0] = 1;
    for (int i = 1; i <= MAXN+1; i++) {
        FAC[i] = FAC[i-1] * i % MOD;
    }

    INV_FAC[MAXN+1] = binexp(FAC[MAXN+1], MOD-2);
    for (int i = MAXN; i >= 0; i--) {
        INV_FAC[i] = INV_FAC[i+1] * (i+1) % MOD;
    }

    for (int n = 0; n <= MAXN+1; n++) {
        for (int k = 0; k <= MAXN+1; k++) {
            ch[n][k] = choose(n, k);
        }
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);

    cin >> n >> k >> t;

    set_up();

    // Base case
    for (int used = 1; used <= n+1; used++) {
        dp[1][used][ch[used][2]] = 1;
    }

    // Do dp
    for (int pused = 1; pused < k; pused++) {
        for (int used = 1; used <= n+1; used++) {
            for (int goodness = 0; goodness <= t; goodness++) {
                // Don't use prefix value
                add(dp[pused + 1][used][goodness], dp[pused][used][goodness])

                // Use prefix value
                for (int new_used = 1;
                     new_used + used <= n+1 and
                     goodness + ch[new_used][2] <= t;
                     new_used++) {
                    add(dp[pused + 1][used + new_used][goodness + ch[new_used][2]],
                        dp[pused][used][goodness] * ch[used-1 + new_used][new_used] % MOD)
                }
            }
        }
    }

    cout << dp[k][n+1][t];
}

詳細信息

Test #1:

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

input:

2 5 1

output:

12

result:

ok 1 number(s): "12"

Test #2:

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

input:

7 10 15

output:

2016

result:

ok 1 number(s): "2016"

Test #3:

score: 0
Accepted
time: 12ms
memory: 14404kb

input:

46 50 171

output:

645560469

result:

ok 1 number(s): "645560469"

Test #4:

score: 0
Accepted
time: 2ms
memory: 20032kb

input:

64 64 0

output:

0

result:

ok 1 number(s): "0"

Test #5:

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

input:

64 64 1

output:

326126263

result:

ok 1 number(s): "326126263"

Test #6:

score: 0
Accepted
time: 4ms
memory: 21056kb

input:

63 64 0

output:

4476118

result:

ok 1 number(s): "4476118"

Test #7:

score: 0
Accepted
time: 4ms
memory: 5672kb

input:

11 45 14

output:

963276342

result:

ok 1 number(s): "963276342"

Test #8:

score: 0
Accepted
time: 13ms
memory: 7904kb

input:

35 20 565

output:

0

result:

ok 1 number(s): "0"

Test #9:

score: 0
Accepted
time: 3ms
memory: 6424kb

input:

3 64 5

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 12ms
memory: 10920kb

input:

35 45 153

output:

181934997

result:

ok 1 number(s): "181934997"

Test #11:

score: 0
Accepted
time: 2ms
memory: 3880kb

input:

3 25 5

output:

0

result:

ok 1 number(s): "0"

Test #12:

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

input:

35 5 373

output:

740122840

result:

ok 1 number(s): "740122840"

Test #13:

score: 0
Accepted
time: 2ms
memory: 6224kb

input:

3 50 5

output:

0

result:

ok 1 number(s): "0"

Test #14:

score: 0
Accepted
time: 21ms
memory: 11572kb

input:

35 30 592

output:

0

result:

ok 1 number(s): "0"

Test #15:

score: 0
Accepted
time: 2ms
memory: 3556kb

input:

3 11 1

output:

540

result:

ok 1 number(s): "540"

Test #16:

score: 0
Accepted
time: 30ms
memory: 14028kb

input:

35 55 352

output:

656633208

result:

ok 1 number(s): "656633208"

Test #17:

score: 0
Accepted
time: 27ms
memory: 14628kb

input:

54 38 356

output:

215089708

result:

ok 1 number(s): "215089708"

Test #18:

score: 0
Accepted
time: 3ms
memory: 7328kb

input:

22 19 189

output:

0

result:

ok 1 number(s): "0"

Test #19:

score: 0
Accepted
time: 68ms
memory: 22828kb

input:

54 63 401

output:

987604839

result:

ok 1 number(s): "987604839"

Test #20:

score: 0
Accepted
time: 5ms
memory: 8120kb

input:

22 43 171

output:

827743481

result:

ok 1 number(s): "827743481"

Test #21:

score: 0
Accepted
time: 23ms
memory: 11868kb

input:

54 24 446

output:

551546514

result:

ok 1 number(s): "551546514"

Test #22:

score: 0
Accepted
time: 2ms
memory: 3864kb

input:

22 4 152

output:

0

result:

ok 1 number(s): "0"

Test #23:

score: 0
Accepted
time: 235ms
memory: 25352kb

input:

54 48 1306

output:

0

result:

ok 1 number(s): "0"

Test #24:

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

input:

22 29 7

output:

374430631

result:

ok 1 number(s): "374430631"

Test #25:

score: 0
Accepted
time: 39ms
memory: 7732kb

input:

54 9 1351

output:

0

result:

ok 1 number(s): "0"

Test #26:

score: 0
Accepted
time: 2ms
memory: 10180kb

input:

22 54 5

output:

267958047

result:

ok 1 number(s): "267958047"

Test #27:

score: 0
Accepted
time: 205ms
memory: 20140kb

input:

64 32 1315

output:

494251101

result:

ok 1 number(s): "494251101"

Test #28:

score: 0
Accepted
time: 8ms
memory: 5584kb

input:

33 12 332

output:

765350074

result:

ok 1 number(s): "765350074"

Test #29:

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

input:

1 57 1

output:

1

result:

ok 1 number(s): "1"

Test #30:

score: 0
Accepted
time: 12ms
memory: 10352kb

input:

33 37 363

output:

0

result:

ok 1 number(s): "0"

Test #31:

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

input:

1 17 0

output:

16

result:

ok 1 number(s): "16"

Test #32:

score: 0
Accepted
time: 17ms
memory: 14692kb

input:

33 62 148

output:

871819399

result:

ok 1 number(s): "871819399"

Test #33:

score: 0
Accepted
time: 2ms
memory: 3812kb

input:

1 42 0

output:

41

result:

ok 1 number(s): "41"

Test #34:

score: 0
Accepted
time: 9ms
memory: 7140kb

input:

33 23 179

output:

23699248

result:

ok 1 number(s): "23699248"

Test #35:

score: 0
Accepted
time: 2ms
memory: 5424kb

input:

1 3 1

output:

1

result:

ok 1 number(s): "1"

Test #36:

score: 0
Accepted
time: 16ms
memory: 12544kb

input:

33 47 211

output:

267909794

result:

ok 1 number(s): "267909794"

Test #37:

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

input:

11 26 32

output:

0

result:

ok 1 number(s): "0"

Test #38:

score: 0
Accepted
time: 9ms
memory: 4972kb

input:

43 6 579

output:

280289125

result:

ok 1 number(s): "280289125"

Test #39:

score: 0
Accepted
time: 4ms
memory: 5864kb

input:

11 50 5

output:

865381083

result:

ok 1 number(s): "865381083"

Test #40:

score: 0
Accepted
time: 50ms
memory: 12812kb

input:

43 31 750

output:

0

result:

ok 1 number(s): "0"

Test #41:

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

input:

11 11 12

output:

753565341

result:

ok 1 number(s): "753565341"

Test #42:

score: 0
Accepted
time: 35ms
memory: 16036kb

input:

43 56 290

output:

575236094

result:

ok 1 number(s): "575236094"

Test #43:

score: 0
Accepted
time: 4ms
memory: 5200kb

input:

11 36 52

output:

0

result:

ok 1 number(s): "0"

Test #44:

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

input:

44 16 0

output:

0

result:

ok 1 number(s): "0"

Test #45:

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

input:

12 61 31

output:

682427534

result:

ok 1 number(s): "682427534"

Test #46:

score: 0
Accepted
time: 21ms
memory: 14968kb

input:

44 41 365

output:

759457870

result:

ok 1 number(s): "759457870"

Test #47:

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

input:

22 19 70

output:

247296498

result:

ok 1 number(s): "247296498"

Test #48:

score: 0
Accepted
time: 84ms
memory: 23516kb

input:

54 64 444

output:

418216086

result:

ok 1 number(s): "418216086"

Test #49:

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

input:

22 44 52

output:

779702126

result:

ok 1 number(s): "779702126"

Test #50:

score: 0
Accepted
time: 118ms
memory: 14880kb

input:

54 25 1303

output:

0

result:

ok 1 number(s): "0"

Test #51:

score: 0
Accepted
time: 3ms
memory: 5848kb

input:

22 5 49

output:

219556981

result:

ok 1 number(s): "219556981"

Test #52:

score: 0
Accepted
time: 221ms
memory: 25644kb

input:

54 49 1269

output:

0

result:

ok 1 number(s): "0"

Test #53:

score: 0
Accepted
time: 2ms
memory: 6240kb

input:

22 30 14

output:

719775605

result:

ok 1 number(s): "719775605"

Test #54:

score: 0
Accepted
time: 48ms
memory: 7884kb

input:

54 10 1314

output:

0

result:

ok 1 number(s): "0"

Test #55:

score: 0
Accepted
time: 7ms
memory: 10236kb

input:

22 54 12

output:

325137058

result:

ok 1 number(s): "325137058"

Test #56:

score: 0
Accepted
time: 163ms
memory: 19288kb

input:

54 35 1359

output:

0

result:

ok 1 number(s): "0"

Test #57:

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

input:

33 13 335

output:

202725820

result:

ok 1 number(s): "202725820"

Test #58:

score: 0
Accepted
time: 688ms
memory: 38220kb

input:

64 64 2080

output:

1

result:

ok 1 number(s): "1"

Test #59:

score: 0
Accepted
time: 2ms
memory: 3392kb

input:

1 1 0

output:

0

result:

ok 1 number(s): "0"

Test #60:

score: 0
Accepted
time: 2ms
memory: 3436kb

input:

1 1 1

output:

1

result:

ok 1 number(s): "1"

Test #61:

score: 0
Accepted
time: 621ms
memory: 36184kb

input:

63 63 2016

output:

1

result:

ok 1 number(s): "1"