generated from Tiphereth-A/TINplate
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b809e4b
commit a659905
Showing
6 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef TIFALIBS_ENUM_GOSPER | ||
#define TIFALIBS_ENUM_GOSPER | ||
|
||
#include "../bit/lowbit.hpp" | ||
|
||
namespace tifa_libs { | ||
|
||
template <u32 ID = 0> | ||
class Gosper { | ||
static inline u32 n_, k_; | ||
u64 now_; | ||
|
||
public: | ||
static constexpr void set(u32 n, u32 k) { | ||
assert(k <= n && n < 64); | ||
n_ = n; | ||
k_ = k; | ||
} | ||
static Gosper begin() { return (1_u64 << k_) - 1; } | ||
static Gosper end() { return 1_u64 << n_; } | ||
|
||
constexpr Gosper(u64 now = *begin()) : now_(now) { assert(now == *end() || std::popcount(now) == k_); } | ||
|
||
constexpr u64 operator*() const { return now_; } | ||
constexpr bool operator!=(Gosper const &x) const { return now_ != x.now_; } | ||
constexpr void operator++() { | ||
u64 c = bit::lowbit(now_), r = now_ + c; | ||
now_ = ((r ^ now_) / 4 / c) | r; | ||
} | ||
}; | ||
|
||
} // namespace tifa_libs | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
title: gosper | ||
documentation_of: //src/code/enum/gosper.hpp | ||
--- |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#define UNITTEST | ||
#define PROBLEM "https://judge.yosupo.jp/problem/aplusb" | ||
|
||
#include "../../../code/enum/gosper.hpp" | ||
|
||
#include "../../../code/comb/binom.hpp" | ||
#include "../../../code/math/mint.hpp" | ||
#include "../../../code/math/mintdata_s30.hpp" | ||
#include "../base.hpp" | ||
|
||
using mint = tifa_libs::math::mint<tifa_libs::math::mintdata_s30<998244353>>; | ||
|
||
template <u32 ID> | ||
void test(u32 n, u32 kmax) { | ||
using Gosper = tifa_libs::Gosper<ID>; | ||
auto binom = tifa_libs::math::Binom<mint>(n); | ||
for (u32 k = 0; k <= kmax; ++k) { | ||
Gosper::set(n, k); | ||
Gosper gs; | ||
u32 cnt = 0, cnt_correct = binom.mCn(n, k).val(); | ||
for (auto i : gs) { | ||
++cnt; | ||
check((u32)std::popcount(i), k, check_param(n), check_param(k), check_param(std::bitset<64>(i).to_string())); | ||
} | ||
check(cnt, cnt_correct, check_param(n), check_param(k)); | ||
} | ||
} | ||
|
||
int main() { | ||
auto tcase = tifa_libs::unittest::pre_test(); | ||
|
||
switch (tcase) { | ||
case tifa_libs::unittest::ts_example_00: test<1>(1, 1); break; | ||
case tifa_libs::unittest::ts_example_01: test<1>(2, 2); break; | ||
case tifa_libs::unittest::ts_random_00: test<1>(3, 3); break; | ||
case tifa_libs::unittest::ts_random_01: test<1>(4, 4); break; | ||
case tifa_libs::unittest::ts_random_02: test<1>(5, 5); break; | ||
case tifa_libs::unittest::ts_random_03: test<1>(6, 6); break; | ||
case tifa_libs::unittest::ts_random_04: test<2>(10, 10); break; | ||
case tifa_libs::unittest::ts_random_05: test<2>(20, 20); break; | ||
case tifa_libs::unittest::ts_random_06: test<2>(30, 10); break; | ||
case tifa_libs::unittest::ts_random_07: test<2>(40, 8); break; | ||
case tifa_libs::unittest::ts_random_08: test<2>(50, 7); break; | ||
case tifa_libs::unittest::ts_random_09: test<2>(60, 6); break; | ||
default: break; | ||
} | ||
|
||
tifa_libs::unittest::post_test(); | ||
} |
Empty file.