C++ Library for Competitive Programming
#include "emthrm/math/twelvefold_way/pascal.hpp"
時間計算量 | |
---|---|
パスカルの三角形 | $O(N^2)$ |
二項係数 | $\langle O(N + \log{M}), O(1) \rangle$ |
二項係数 巨大な $n$ 版 | $O(K + \log{M})$ |
二項係数の数表 巨大な $n$ 版 | $O(K)$ |
名前 | 戻り値 |
---|---|
template <typename T> std::vector<std::vector<T>> pascal(const int n);
|
$n$ 段のパスカルの三角形 |
名前 | 戻り値 |
---|---|
template <unsigned int T> std::vector<MInt<T>> large_nCk_init(long long n, const int k);
|
$\binom{n}{r}$ ($0 \leq r \leq k$) の数表 |
http://drken1215.hatenablog.com/entry/2018/06/08/210000
パスカルの三角形
#ifndef EMTHRM_MATH_TWELVEFOLD_WAY_PASCAL_HPP_
#define EMTHRM_MATH_TWELVEFOLD_WAY_PASCAL_HPP_
#include <vector>
namespace emthrm {
template <typename T>
std::vector<std::vector<T>> pascal(const int n) {
std::vector<std::vector<T>> c(n + 1, std::vector<T>(n + 1, 0));
for (int i = 0; i <= n; ++i) {
c[i][0] = 1;
for (int j = 1; j <= i; ++j) {
c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
}
}
return c;
}
} // namespace emthrm
#endif // EMTHRM_MATH_TWELVEFOLD_WAY_PASCAL_HPP_
#line 1 "include/emthrm/math/twelvefold_way/pascal.hpp"
#include <vector>
namespace emthrm {
template <typename T>
std::vector<std::vector<T>> pascal(const int n) {
std::vector<std::vector<T>> c(n + 1, std::vector<T>(n + 1, 0));
for (int i = 0; i <= n; ++i) {
c[i][0] = 1;
for (int j = 1; j <= i; ++j) {
c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
}
}
return c;
}
} // namespace emthrm