【补题日记】[2022牛客暑期多校1]I-Chiitoitsu

本文介绍了一种扑克牌游戏策略,通过状态转移方程求解摸牌后期望得分,关键在于丢弃规则:尽量组成对。代码展示了如何计算初始单牌情况下赢得比赛的期望值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Pro

https://ac.nowcoder.com/acm/contest/33186/I

Sol

最优策略:摸到的牌如果可以组成对,则丢一张单牌;否则丢掉这张牌

f s , r f_{s,r} fs,r表示当手牌中有 s s s张单牌,牌堆中剩余 r r r张牌时的期望,状态转移方程为:
在这里插入图片描述
则答案为 f 初始手牌中单牌个数 , 136 − 13 f_{初始手牌中单牌个数,136-13} f初始手牌中单牌个数,13613

Code

//By cls1277
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define Fo(i,a,b) for(LL i=(a); i<=(b); i++)
#define Ro(i,b,a) for(LL i=(b); i>=(a); i--)
#define Eo(i,x,_) for(LL i=head[x]; i; i=_[i].next)
#define Ms(a,b) memset((a),(b),sizeof(a))
#define endl '\n'

const LL mod = 1e9+7;
LL f[15][140];

LL qpow(LL x, LL y) {
    LL z = 1;
    while(y) {
        if(y&1) z = z*x%mod;
        x = x*x%mod;
        y >>= 1;
    }
    return z%mod;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef DEBUG
    freopen("data.txt","r",stdin);
    #endif
    for(int i=1; i<=13; i+=2) {
        Fo(j,1,136) {
            if(i==1) f[i][j] = (1+f[1][j-1]*(j-3)%mod*qpow(j,mod-2)%mod)%mod;
            else f[i][j] = (1+f[i-2][j-1]*3%mod*i%mod*qpow(j,mod-2)%mod+f[i][j-1]*(j-3*i)%mod*qpow(j,mod-2)%mod)%mod;
        }
    }
    LL t; cin>>t;
    Fo(tt, 1, t) {
        string str; cin>>str;
        map<string, LL> s;
        for(int i=0; i<str.length(); i+=2) {
            string ss = "";
            ss += str[i]; ss += str[i+1];
            s[ss]++;
        }
        LL cnt = 0;
        for(auto it:s) {
            if(it.second&1) {
                cnt++;
            }
        }
        cout<<"Case #"<<tt<<": "<<f[cnt][123]<<endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cls1277

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值