Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // An AC a day keeps the doctor away.
- #pragma GCC optimize("Ofast")
- #include <bits/stdc++.h>
- #ifdef local
- #define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
- #define debug(args...) qqbx(#args, args)
- #define orange(args...) danb(#args, args)
- using std::cerr;
- template <typename ...T> void qqbx(const char *s, T ...args) {
- int cnt = sizeof...(T);
- ((cerr << "\e[1;32m(" << s << ") = ("), ..., (cerr << args << (--cnt ? ", " : ")\e[0m\n")));
- }
- template <typename T> void danb(const char *s, T L, T R) {
- cerr << "\e[1;32m[ " << s << " ] = [ ";
- for (int f = 0; L != R; ++L) cerr << (f++ ? ", " : "") << *L;
- cerr << " ]\e[0m\n";
- }
- #else
- #define safe ((void)0)
- #define debug(...) ((void)0)
- #define orange(...) ((void)0)
- #endif // local
- #define all(v) begin(v),end(v)
- using namespace std;
- using ld = long double;
- const function<int(int [5])> combs[] = {
- // Aces
- [](int a[]) {
- int res = 0;
- for (int i = 0; i < 5; i++) if (a[i] == 1) res += 1;
- return res;
- },
- // Deuces
- [](int a[]) {
- int res = 0;
- for (int i = 0; i < 5; i++) if (a[i] == 2) res += 2;
- return res;
- },
- // Threes
- [](int a[]) {
- int res = 0;
- for (int i = 0; i < 5; i++) if (a[i] == 3) res += 3;
- return res;
- },
- // Fours
- [](int a[]) {
- int res = 0;
- for (int i = 0; i < 5; i++) if (a[i] == 4) res += 4;
- return res;
- },
- // Fives
- [](int a[]) {
- int res = 0;
- for (int i = 0; i < 5; i++) if (a[i] == 5) res += 5;
- return res;
- },
- // Sixes
- [](int a[]) {
- int res = 0;
- for (int i = 0; i < 5; i++) if (a[i] == 6) res += 6;
- return res;
- },
- // choice
- [](int a[]) {
- int res = 0;
- for (int i = 0; i < 5; i++) res += a[i];
- return res;
- },
- // 4 of a kind
- [](int a[]) {
- sort(a, a+5);
- int res = 0;
- if (a[0] == a[3] || a[1] == a[4])
- for (int i = 0; i < 5; i++) res += a[i];
- return res;
- },
- // Full house
- [](int a[]) {
- sort(a, a+5);
- int res = 0;
- if ((a[0] == a[2] && a[3] == a[4]) || (a[0] == a[1] && a[2] == a[4]))
- for (int i = 0; i < 5; i++) res += a[i];
- return res;
- },
- // S straight
- [](int a[]) {
- bool has[7] = {};
- for (int i = 0; i < 5; i++)
- has[a[i]] = true;
- for (int i: {1, 2, 3})
- if (has[i] && has[i+1] && has[i+2] && has[i+3])
- return 15;
- return 0;
- },
- // B straight
- [](int a[]) {
- sort(a, a+5);
- bool ok1 = true, ok2 = true;
- for (int i = 0; i < 5; i++) {
- if (a[i] != i+1)
- ok1 = false;
- if (a[i] != i+2)
- ok2 = false;
- }
- if (ok1 || ok2)
- return 30;
- return 0;
- },
- // Yacht
- [](int a[]) {
- sort(a, a+5);
- if (a[0] == a[4])
- return 50;
- return 0;
- }
- };
- bool available[12];
- int score(int s) {
- int dice[5];
- for (int i = 0; i < 5; i++) {
- int d = s >> (i * 3) & 7;
- assert (1 <= d && d <= 6);
- dice[i] = d;
- }
- int res = 0;
- for (int i = 0; i < 12; i++)
- if (available[i])
- res = max(res, combs[i](dice));
- return res;
- }
- bool vis[3][1 << 15];
- ld dp[3][1 << 15];
- vector<int> enumerate(int x) {
- if (x == 0)
- return {0};
- vector<int> res, f = enumerate(x-1);
- for (int i = 1; i <= 6; i++)
- for (int d: f)
- res.emplace_back(d << 3 | i);
- // for (int p: res) debug(bitset<15>(p));
- return res;
- }
- ld dfs(int t, int fixed) {
- if (vis[t][fixed]) return dp[t][fixed];
- vis[t][fixed] = true;
- int cnt = 0;
- for (int i = 0; i < 5; i++) {
- if (!(fixed >> (i * 3) & 7)) {
- ++cnt;
- }
- }
- auto E = enumerate(cnt);
- for (int p: E) {
- int s = fixed;
- for (int i = 0; i < 5; i++) {
- if (!(fixed >> (i * 3) & 7)) {
- s |= (p & 7) << (i * 3);
- p >>= 3;
- }
- }
- ld best = 0;
- if (t == 2)
- best = score(s);
- else
- for (int keep = 0; keep < (1 << 5); keep++) {
- int mask = 0;
- for (int i = 0; i < 5; i++)
- if (keep >> i & 1)
- mask |= 7 << (i * 3);
- best = max(best, dfs(t+1, s & mask));
- }
- dp[t][fixed] += best / ld(E.size());
- }
- return dp[t][fixed];
- }
- signed main() {
- ios_base::sync_with_stdio(0), cin.tie(0);
- int t, s = 0;
- cin >> t;
- for (int i = 0; i < 5; i++) {
- int x;
- cin >> x;
- s |= x << (i * 3);
- }
- string avail;
- cin >> avail;
- for (int i = 0; i < 12; i++)
- available[i] = (avail[i] == '1');
- cout << fixed << setprecision(10);
- if (t == 3) {
- cout << score(s) << '\n';
- } else if (t == 0) {
- cout << dfs(0, 0) << '\n';
- } else {
- cout << dfs(t-1, s) << '\n';
- }
- }
Add Comment
Please, Sign In to add comment