当前位置:网站首页>22 Niu Ke Duo School 1 I. Chiitoitsu (Probability dp)
22 Niu Ke Duo School 1 I. Chiitoitsu (Probability dp)
2022-08-01 07:27:00 【Cherry blossoms with two petals Qilixiang】
Approximate meaning of the title: The initial hand has 13 cards, up to two of the same card, a total of 34 kinds of cards, 4 cards of each kind, every time you draw cards from the deck, you are required to make seven pairs,That is to say, if you get seven pairs of the same card, find the number of rounds to reach seven pairs under the optimal strategy
Thinking: Classic probability dp, the optimal strategy is God's perspective, and will not lose the existing single card (that is, assuming that I must touch the existing single row to make a pair)
Considering the state dp[i][j], it means the number of rounds to reach the final state when there are i single cards in hand and j cards in the deck
, dp[i][j] = p1*dp[i-2][j-1] + p2*dp[i][j-1] + 1
p1 means that a card drawn from the deck just forms a pair with a card in the hand, hand-2 deck-1, the probability is 3*i/j
p2 means that a card drawn from the deck does not form a pair with the cards in the hand, and the cards are discarded directly. The hand remains unchanged, the deck is -1, and the probability is (j-3*i)/j
+1 means draw a card
Initialize the final state dp[1][i] = p*dp[1][i-1] + 1, when there is only one card left, that is, when the game is over, draw cards from the deck, if you make a pairThen it ends. If you don't make a pair to continue the deck -1, the probability is (i-3)/i, +1 means to draw a card
Because the answer is modulo, consider the multiplication inverse instead of division, and use fast exponentiation to speed up, the code is as follows:
#include using namespace std;stringstream ss;#define endl "\n"typedef long long ll;typedef pair PII;typedef pair, int> PIII;const int N = 1e5+10, M = 30, mod = 1e9+7;const int INF = 0x3f3f3f3f;int t,T;int n;ll dp[20][200]; // dp[i][j] represents the expectation of reaching the final state when there are i single cards in hand and j cards in the deckll qmi(ll a, ll k){ll res = 1;while(k){if(k & 1) res = res * a % mod;k>>=1;a = a*a % mod;}return res;}void solve(){map mp;string s;cin >> s;int cnt = 0;// Calculate the number of single cards in the initial handfor(int i = 0; i>T;t = T;while(T -- ){solve();}} 边栏推荐
猜你喜欢

How to generate and configure public key certificate in Alipay

rhcsa 第三次

企业员工人事管理系统(数据库课设)
![Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]](/img/7f/08b323ffc5b5f8e3354bee6775b994.png)
Explosive 30,000 words, the hardest core丨Mysql knowledge system, complete collection of commands [recommended collection]

Guest brush SQL - 2

Practical training Navicat Chinese and English mode switching

curl (7) Failed connect to localhost8080; Connection refused

crypto-js uses

Electromagnetic compatibility introductory tutorial (6) test project

我三本学历,五面阿里,被面试官“供”着出来了,拿了33*15的Offer
随机推荐
最小生成树
聊一聊ICMP协议以及ping的过程
Detailed explanation of the crawler framework Scrapy
Bean的生命周期
my creative day
Golang: go open web service
Golang:go获取url和表单属性值
阿里三面:MQ 消息丢失、重复、积压问题,该如何解决?
并发编程13-JUC之CountDownLatch
app 自动化 通过工具查看app 元素 (三)
Introduction to the basic principles, implementation and problem solving of crawler
小程序全面屏手势配置案例
Golang: go static file processing
Srping中bean的生命周期
旋度(7)连接失败localhost8080;连接拒绝了
pytest接口自动化测试框架 | parametrize中ids的用法
牛客刷SQL---2
Information system project managers must recite the work of the core test site (56) Configuration Control Board (CCB)
Delphi MDI appliction 文档最大化显示、去掉最大化最小化等按钮
MySQL row locks and gap locks