kyopro-lib

This documentation is automatically generated by online-judge-tools/verification-helper

View on GitHub

:x: Partition number (Enumerate $P(n, k)$)
(Mylib/Combinatorics/partition_number.cpp)

Operations

Requirements

Notes

Problems

References

Verified with

Code

#pragma once
#include <vector>

namespace haar_lib {
  template <typename T>
  auto partition_number(int n, int k) -> std::vector<std::vector<T>> {
    std::vector<std::vector<T>> dp(n + 1, std::vector<T>(k + 1));
    dp[0][0] = 1;

    for (int i = 0; i <= n; ++i) {
      for (int j = 1; j <= k; ++j) {
        if (i - j >= 0)
          dp[i][j] = dp[i][j - 1] + dp[i - j][j];
        else
          dp[i][j] = dp[i][j - 1];
      }
    }

    return dp;
  }
}  // namespace haar_lib
#line 2 "Mylib/Combinatorics/partition_number.cpp"
#include <vector>

namespace haar_lib {
  template <typename T>
  auto partition_number(int n, int k) -> std::vector<std::vector<T>> {
    std::vector<std::vector<T>> dp(n + 1, std::vector<T>(k + 1));
    dp[0][0] = 1;

    for (int i = 0; i <= n; ++i) {
      for (int j = 1; j <= k; ++j) {
        if (i - j >= 0)
          dp[i][j] = dp[i][j - 1] + dp[i - j][j];
        else
          dp[i][j] = dp[i][j - 1];
      }
    }

    return dp;
  }
}  // namespace haar_lib
Back to top page