CSES - Putka Open 2020 – 2/5 - Results
Submission details
Task:Planeetat
Sender:jnalanko
Submission time:2020-09-27 05:04:50 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp:8:10: fatal error: stdlib_printing.hh: No such file or directory
 #include "stdlib_printing.hh"
          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.

Code

#include <iostream>
#include <vector>
#include <cassert>
#include <set>
#include <cmath>
#include <unordered_map>
#include <utility>
#include "stdlib_printing.hh"

typedef long long LL;

using namespace std;

LL mod = 1e9+7;

map<pair<LL,LL>, LL> nCr_memo;
LL nCr(LL n, LL k){
    if(n == k || k == 0) return 1;
    if(nCr_memo.find({n,k}) != nCr_memo.end()) return nCr_memo[{n,k}];
    LL ans = nCr(n-1,k) + nCr(n-1,k-1);
    ans %= mod;
    nCr_memo[{n,k}] = ans;
    return ans;
}

map<pair<LL,LL>, LL> F_memo;
LL F(LL n,LL k){
    if(n == 0 && k == 0) return 1;
    if(k == 0) return 0;
    if(n == 0) return 1;
    if(F_memo.find({n,k}) != F_memo.end())
        return F_memo[{n,k}];
    LL ans = 0;
    for(LL s = 1; s <= n; s++){
        ans += nCr(n,s) * pow(k,s) * F(n-s,s);
    }
    ans %= mod;
    F_memo[{n,k}] = ans;
    return ans;
}

int main(){
    vector<vector<LL > > stirling(100+1,vector<LL>(100+1));
    stirling[0][0] = 1; // S(n,k) = number of permutations of n elements with k cycles
    for(LL n = 1; n <= 100; n++){
        for(LL k = 1; k <= 100; k++){
            stirling[n][k] = ((n-1)*stirling[n-1][k] + stirling[n-1][k-1]) % mod;
        }
    }

    vector<vector<LL > > nCr(100+1,vector<LL>(100+1)); // n choose k
    nCr[0][0] = 1;
    for(LL n = 1; n <= 100; n++){
        for(LL k = 0; k <= n; k++){
            nCr[n][k] += nCr[n-1][k];
            if(k > 0) nCr[n][k] += nCr[n-1][k-1];
            nCr[n][k] %= mod;
        }
    }

    LL n; cin >> n;

    for(LL k = 1; k <= n; k++){
        LL ans = 0;
        for(LL r = k; r <= n; r++){
            // r = size of the part with the cycles
            ans += (nCr[n][r] * stirling[r][k] % mod) * F(n-r,r) % mod;
            ans %= mod;
        }
        cout << ans << endl;
    }
}