c++ 3

순열 (Permutation)

1. 순서가 중요한 완전 탐색에 종종 사용된다. 2. 개수가 고정된 선택 문제를 순열로 바꿔서 풀 수 있다. (조합-Combination으로 활용 가능) (BOJ6603 로또 , https://www.acmicpc.net/problem/6603) # std::next_permutation, std::prev_permutation C++은 std::next_permutation, std::prev_permutation로 사전순(lexicographically ordered)의 다음 순열, 이전 순열을 제공한다. # Time Complexity 한 번 호출하면 O(n), 모든 가능성을 전부 호출하면 Amortized O(1) https://stackoverflow.com/questions/4973077/th..

[A tour of C++] Ch 14. Numerics

14.5 Random Numbers 난수 생성기는 크게 두 부분으로 구성된다. - engine: 난수 또는 psuedo-난수의 시퀀스를 생성함 - distribution: 이러한 값을 어떤 범위 안의 수학적 분포로 매핑함 #include #include #include #include using namespace std; class Rand_int { public: Rand_int(int low = numeric_limits::min(), int high = numeric_limits::max()) : rd{}, rnd{rd()}, dist{low, high} {} int operator()() { return dist(rnd); } private: random_device rd; mt19937 rnd;..

Programming/C++ 2020.01.15