当前位置:网站首页>"Weilai Cup" 2022 Niuke summer multi school training camp 1 I chiitoitsu (probability DP)
"Weilai Cup" 2022 Niuke summer multi school training camp 1 I chiitoitsu (probability DP)
2022-07-21 01:50:00 【Snow_ raw】
" Weilai cup "2022 Niuke summer multi school training camp 1 I Chiitoitsu( probability dp)
The question : The beginning is for you 13 13 13 card , At most two cards of the same card . Add what you have 13 13 13 The total number of cards is 136 136 136 Zhang , That is, there are 34 34 34 Types , Each type of card has 4 4 4 Zhang . Make up 7 7 7 What are the expectations for different types of cards
Ideas : First of all, the given string for each test is Unique , And the same number of cards is up to two . So obviously, as long as the number of cards to start is 2 2 2 The cards appear the same number of times , No matter what brand , Then the final expectation is the same . We are thinking about using probability dp To solve this problem . hypothesis d p [ i ] [ j ] dp[i][j] dp[i][j] , i i i It refers to the number of cards on hand 2 2 2 The number of cards , j j j It refers to how many cards can be selected on the desktop , That is, the initial number of cards that can be selected is 136 − 13 = 123 136-13=123 136−13=123 , Then assume that the number of cards in the string is 2 2 2 The number of cards is i i i, Then our ultimate expectation is d p [ i ] [ 123 ] dp[i][123] dp[i][123] . So what we need to do is pretreatment d p dp dp Array . Is the total O ( 7 ∗ 123 ) O(7*123) O(7∗123) Complexity , Then count the number of cards played each time 2 2 2 The number of cards , then O ( 1 ) O(1) O(1) Query can be . Next we deduce dp Transfer equation The best strategy is to have a single hand , We will play single row , Then get a card and form a pair with another card in your hand . namely d p [ i ] [ j ] + = d p [ i + 1 ] [ j − 1 ] dp[i][j]+=dp[i+1][j-1] dp[i][j]+=dp[i+1][j−1] ∗ * ∗ ( The probability of getting a pair ) ( The probability of getting a pair ) ( The probability of getting a pair ), Another situation is that you take a card from the table but can't form a pair , Play this card, that is d p [ i ] [ j ] + = d p [ i ] [ j − 1 ] dp[i][j]+=dp[i][j-1] dp[i][j]+=dp[i][j−1] ∗ * ∗ ( The probability of not getting a pair ) ( The probability of not getting a pair ) ( The probability of not getting a pair ). So the transfer equation is d p [ i ] [ j ] = d [ i + 1 ] [ j − 1 ] dp[i][j]=d[i+1][j-1] dp[i][j]=d[i+1][j−1] ∗ * ∗ ( The probability of getting a pair ) ( The probability of getting a pair ) ( The probability of getting a pair ) + d p [ i ] [ j − 1 ] dp[i][j-1] dp[i][j−1] ∗ * ∗ ( The probability of not getting a pair ) ( The probability of not getting a pair ) ( The probability of not getting a pair ).
Code :
/* * @author: Snow * @LastEditTime: 2022-07-19 16:39:26 * @Description: Algorithm Contest */
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#pragma GCC optimize(3)
typedef pair<int,int>PII;
#define pb emplace_back
int dp[10][150];
const int mod = 1e9+7;
map<string,int>mp;
int qmi(int a,int b){
int res=1;
while(b){
if(b&1)res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
void init(){
for(int i=6;i>=0;i--){
int good=(13-i*2)*3;
for(int j=good;j<=123;j++){
int bad=j-good;
int fact=qmi(j,mod-2);
dp[i][j]=(dp[i+1][j-1]*good%mod*fact%mod+dp[i][j-1]*bad%mod*fact%mod+1)%mod;
}
}
}
signed main(){
init();
int T;
cin>>T;
for(int _=1;_<=T;_++){
string s;
cin>>s;
mp.clear();
int sum=0;
string ss;
for(int i=0;i<s.size();i+=2){
ss="";
ss+=s[i];
ss+=s[i+1];
mp[ss]++;if(mp[ss]>1)sum++;
}
printf("Case #%lld: %lld\n",_,dp[sum][123]);
}
return 0;
}
边栏推荐
- At32 MCU f415 OTG new function use
- Record of force deduction and question brushing 2---35 Search insertion location
- 干货丨重中之重:数据分析中常用指标及术语!
- Ampere Altra Max 提供可持续的高分辨率 H.265 编码
- C——变量的作用域与存储类
- [03] let's talk about "performance" through your CPU frequency?
- 力扣刷题记录1-----704.二分查找
- Network security - comprehensive penetration test -cve-2019-15107-webmin remote code execution
- VMware安装
- Shardingsphere proxy with mogdb/opengauss to realize distributed database
猜你喜欢
AT32使用内核DWT寄存器设定延时时间
371页20万字2021版智慧城市信息化综合建设方案
Matlab summary of differential equation solving methods
[03] let's talk about "performance" through your CPU frequency?
力扣刷题26. 删除有序数组中的重复项
[trivia] about some unity editors, they lack the tiles option when creating tile maps
Network security in Secondary Vocational Schools - the thinking of reverse PE reverse problem solving in 2022 National Games
matlab-微分方程求解方法汇总
最高的评价:您要走的开发事业道路做事的决心,行动是彻底的,诚恳的和绝对真实的
力扣343-整数分割——动态规划
随机推荐
【读后感】NIO 的相关博客
Series operations of map/multimap container
力扣刷题14. 最长公共前缀
Miller gingival recession and mucogingival junction
【服务器数据恢复】某品牌ProLiant服务器raid瘫痪数据库文件损坏的数据恢复
371页20万字2021版智慧城市信息化综合建设方案
[trivia] about some unity editors, they lack the tiles option when creating tile maps
LeetCode.1217. 玩筹码____简单贪心
原生高性能抓包工具Proxyman,送给爱学习的你
Network security in Secondary Vocational Schools - the thinking of reverse PE reverse problem solving in 2022 National Games
clion创建第一个C项目
Network security comprehensive penetration test cve-2019-7238-nexus remote code execution
在vscode里面使用tinymce富文本编辑器
LeetCode. 302 weekly games___ 01_ 6120. How many pairs can an array form__ Simple hash
Configure dual database
一条代码带大家绘制交互式+pdf+png等多格式桑基美图
LeetCode. 558. Intersection of quadtrees___ Divide and conquer
力扣刷题记录3-----34.在排序数组中查找元素的第一个和最后一个位置
After reading this article, you should thoroughly understand how to do interface testing
展锐手机解锁