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

Compiler report

input/code.cpp:16:1: error: 'map' does not name a type
 map<pair<LL,LL>, LL> nCr_memo;
 ^~~
input/code.cpp: In function 'LL nCr(LL, LL)':
input/code.cpp:19:8: error: 'nCr_memo' was not declared in this scope
     if(nCr_memo.find({n,k}) != nCr_memo.end()) return nCr_memo[{n,k}];
        ^~~~~~~~
input/code.cpp:22:5: error: 'nCr_memo' was not declared in this scope
     nCr_memo[{n,k}] = ans;
     ^~~~~~~~
input/code.cpp: At global scope:
input/code.cpp:26:1: error: 'map' does not name a type
 map<pair<LL,LL>, LL> F_memo;
 ^~~
input/code.cpp: In function 'LL F(LL, LL)':
input/code.cpp:31:8: error: 'F_memo' was not declared in this scope
     if(F_memo.find({n,k}) != F_memo.end())
        ^~~~~~
input/code.cpp:38:5: error: 'F_memo' was not declared in this scope
     F_memo[{n,k}] = ans;
     ^~~~~~

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;
    }
}