bingxuan9112

Yacht

Sep 19th, 2021 (edited)
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.17 KB | None | 0 0
  1. // An AC a day keeps the doctor away.
  2. #pragma GCC optimize("Ofast")
  3. #include <bits/stdc++.h>
  4. #ifdef local
  5. #define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
  6. #define debug(args...) qqbx(#args, args)
  7. #define orange(args...) danb(#args, args)
  8. using std::cerr;
  9. template <typename ...T> void qqbx(const char *s, T ...args) {
  10.     int cnt = sizeof...(T);
  11.     ((cerr << "\e[1;32m(" << s << ") = ("), ..., (cerr << args << (--cnt ? ", " : ")\e[0m\n")));
  12. }
  13. template <typename T> void danb(const char *s, T L, T R) {
  14.     cerr << "\e[1;32m[ " << s << " ] = [ ";
  15.     for (int f = 0; L != R; ++L) cerr << (f++ ? ", " : "") << *L;
  16.     cerr << " ]\e[0m\n";
  17. }
  18. #else
  19. #define safe ((void)0)
  20. #define debug(...) ((void)0)
  21. #define orange(...) ((void)0)
  22. #endif // local
  23. #define all(v) begin(v),end(v)
  24.  
  25. using namespace std;
  26. using ld = long double;
  27.  
  28. const function<int(int [5])> combs[] = {
  29.     // Aces
  30.     [](int a[]) {
  31.         int res = 0;
  32.         for (int i = 0; i < 5; i++) if (a[i] == 1) res += 1;
  33.         return res;
  34.     },
  35.     // Deuces
  36.     [](int a[]) {
  37.         int res = 0;
  38.         for (int i = 0; i < 5; i++) if (a[i] == 2) res += 2;
  39.         return res;
  40.     },
  41.     // Threes
  42.     [](int a[]) {
  43.         int res = 0;
  44.         for (int i = 0; i < 5; i++) if (a[i] == 3) res += 3;
  45.         return res;
  46.     },
  47.     // Fours
  48.     [](int a[]) {
  49.         int res = 0;
  50.         for (int i = 0; i < 5; i++) if (a[i] == 4) res += 4;
  51.         return res;
  52.     },
  53.     // Fives
  54.     [](int a[]) {
  55.         int res = 0;
  56.         for (int i = 0; i < 5; i++) if (a[i] == 5) res += 5;
  57.         return res;
  58.     },
  59.     // Sixes
  60.     [](int a[]) {
  61.         int res = 0;
  62.         for (int i = 0; i < 5; i++) if (a[i] == 6) res += 6;
  63.         return res;
  64.     },
  65.     // choice
  66.     [](int a[]) {
  67.         int res = 0;
  68.         for (int i = 0; i < 5; i++) res += a[i];
  69.         return res;
  70.     },
  71.     // 4 of a kind
  72.     [](int a[]) {
  73.         sort(a, a+5);
  74.         int res = 0;
  75.         if (a[0] == a[3] || a[1] == a[4])
  76.             for (int i = 0; i < 5; i++) res += a[i];
  77.         return res;
  78.     },
  79.     // Full house
  80.     [](int a[]) {
  81.         sort(a, a+5);
  82.         int res = 0;
  83.         if ((a[0] == a[2] && a[3] == a[4]) || (a[0] == a[1] && a[2] == a[4]))
  84.             for (int i = 0; i < 5; i++) res += a[i];
  85.         return res;
  86.     },
  87.     // S straight
  88.     [](int a[]) {
  89.         bool has[7] = {};
  90.         for (int i = 0; i < 5; i++)
  91.             has[a[i]] = true;
  92.         for (int i: {1, 2, 3})
  93.             if (has[i] && has[i+1] && has[i+2] && has[i+3])
  94.                 return 15;
  95.         return 0;
  96.     },
  97.     // B straight
  98.     [](int a[]) {
  99.         sort(a, a+5);
  100.         bool ok1 = true, ok2 = true;
  101.         for (int i = 0; i < 5; i++) {
  102.             if (a[i] != i+1)
  103.                 ok1 = false;
  104.             if (a[i] != i+2)
  105.                 ok2 = false;
  106.         }
  107.         if (ok1 || ok2)
  108.             return 30;
  109.         return 0;
  110.     },
  111.     // Yacht
  112.     [](int a[]) {
  113.         sort(a, a+5);
  114.         if (a[0] == a[4])
  115.             return 50;
  116.         return 0;
  117.     }
  118. };
  119.  
  120. bool available[12];
  121. int score(int s) {
  122.     int dice[5];
  123.     for (int i = 0; i < 5; i++) {
  124.         int d = s >> (i * 3) & 7;
  125.         assert (1 <= d && d <= 6);
  126.         dice[i] = d;
  127.     }
  128.     int res = 0;
  129.     for (int i = 0; i < 12; i++)
  130.         if (available[i])
  131.             res = max(res, combs[i](dice));
  132.     return res;
  133. }
  134.  
  135. bool vis[3][1 << 15];
  136. ld dp[3][1 << 15];
  137. vector<int> enumerate(int x) {
  138.     if (x == 0)
  139.         return {0};
  140.     vector<int> res, f = enumerate(x-1);
  141.     for (int i = 1; i <= 6; i++)
  142.         for (int d: f)
  143.             res.emplace_back(d << 3 | i);
  144.     // for (int p: res) debug(bitset<15>(p));
  145.     return res;
  146. }
  147. ld dfs(int t, int fixed) {
  148.     if (vis[t][fixed]) return dp[t][fixed];
  149.     vis[t][fixed] = true;
  150.     int cnt = 0;
  151.     for (int i = 0; i < 5; i++) {
  152.         if (!(fixed >> (i * 3) & 7)) {
  153.             ++cnt;
  154.         }
  155.     }
  156.     auto E = enumerate(cnt);
  157.     for (int p: E) {
  158.         int s = fixed;
  159.         for (int i = 0; i < 5; i++) {
  160.             if (!(fixed >> (i * 3) & 7)) {
  161.                 s |= (p & 7) << (i * 3);
  162.                 p >>= 3;
  163.             }
  164.         }
  165.         ld best = 0;
  166.         if (t == 2)
  167.             best = score(s);
  168.         else
  169.             for (int keep = 0; keep < (1 << 5); keep++) {
  170.                 int mask = 0;
  171.                 for (int i = 0; i < 5; i++)
  172.                     if (keep >> i & 1)
  173.                         mask |= 7 << (i * 3);
  174.                 best = max(best, dfs(t+1, s & mask));
  175.             }
  176.         dp[t][fixed] += best / ld(E.size());
  177.     }
  178.     return dp[t][fixed];
  179. }
  180. signed main() {
  181.     ios_base::sync_with_stdio(0), cin.tie(0);
  182.     int t, s = 0;
  183.     cin >> t;
  184.     for (int i = 0; i < 5; i++) {
  185.         int x;
  186.         cin >> x;
  187.         s |= x << (i * 3);
  188.     }
  189.     string avail;
  190.     cin >> avail;
  191.     for (int i = 0; i < 12; i++)
  192.         available[i] = (avail[i] == '1');
  193.  
  194.     cout << fixed << setprecision(10);
  195.     if (t == 3) {
  196.         cout << score(s) << '\n';
  197.     } else if (t == 0) {
  198.         cout << dfs(0, 0) << '\n';
  199.     } else {
  200.         cout << dfs(t-1, s) << '\n';
  201.     }
  202. }
  203.  
Add Comment
Please, Sign In to add comment