cp-library

C++ Library for Competitive Programming

View the Project on GitHub emthrm/cp-library

:warning: 数学/写像12相/パスカルの三角形
(test/math/twelvefold_way/pascal.test.cpp)

Depends on

Code

/*
 * @title 数学/写像12相/パスカルの三角形
 *
 * verification-helper: IGNORE
 * verification-helper: PROBLEM https://atcoder.jp/contests/abc254/tasks/abc254_b
 */

#include <iostream>
#include <vector>

#include "emthrm/math/twelvefold_way/pascal.hpp"

int main() {
  int n;
  std::cin >> n;
  const std::vector<std::vector<int>> ans = emthrm::pascal<int>(n - 1);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= i; ++j) {
      std::cout << ans[i][j] << " \n"[j == i];
    }
  }
  return 0;
}
#line 1 "test/math/twelvefold_way/pascal.test.cpp"
/*
 * @title 数学/写像12相/パスカルの三角形
 *
 * verification-helper: IGNORE
 * verification-helper: PROBLEM https://atcoder.jp/contests/abc254/tasks/abc254_b
 */

#include <iostream>
#include <vector>

#line 1 "include/emthrm/math/twelvefold_way/pascal.hpp"



#line 5 "include/emthrm/math/twelvefold_way/pascal.hpp"

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


#line 12 "test/math/twelvefold_way/pascal.test.cpp"

int main() {
  int n;
  std::cin >> n;
  const std::vector<std::vector<int>> ans = emthrm::pascal<int>(n - 1);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= i; ++j) {
      std::cout << ans[i][j] << " \n"[j == i];
    }
  }
  return 0;
}
Back to top page