memoCont

メモ化ライブラリ

std.functional.memoizeとは違い, 引数が連続している必要がある. ハッシュテーブルではなく配列で値を保存するため高速である.

Members

Aliases

Args
alias Args = ParameterTypeTuple!pred
Undocumented in source.
R
alias R = ReturnType!pred
Undocumented in source.

Functions

init
void init(int[2][N] rng)
Undocumented in source. Be warned that the author may not have intended to support it.
opCall
R opCall(Args args)
Undocumented in source. Be warned that the author may not have intended to support it.

Static variables

N
auto N;
Undocumented in source.

Variables

dp
R[] dp;
Undocumented in source.
len
int[N] len;
Undocumented in source.
used
bool[] used;
Undocumented in source.

Examples

import dkh.numeric.primitive;
import dkh.modint;
alias Mint = ModInt!(10^^9+7);

struct A {
    static auto fact = factTable!Mint(100);
    static auto iFac = invFactTable!Mint(100);
    static Mint C1(int n, int k) {
        return fact[n] * iFac[k] * iFac[n-k];
    }

    // メモ化再帰でnCkの計算をする
    static memoCont!C2base C2;
    static Mint C2base(int n, int k) {
        if (k == 0) return Mint(1);
        if (n == 0) return Mint(0);
        return C2(n-1, k-1) + C2(n-1, k);
    }
}

// 0 <= n <= 99, 0 <= k <= 99, 閉区間
A.C2.init([[0, 99], [0, 99]]);
foreach (i; 0..100) {
    foreach (j; 0..i+1) {
        assert(A.C1(i, j) == A.C2(i, j));
    }
}

Meta