当前位置:网站首页>暑期牛客多校1: I Chiitoitsu(期望dp,求逆元)
暑期牛客多校1: I Chiitoitsu(期望dp,求逆元)
2022-07-24 18:36:00 【愚者的黄昏】
基本题意:
一共136张牌(每个花色四张),初始从牌堆中任给13张牌作为手牌,且每个花色的牌不超过两张,每次摸一张牌,然后从14张牌中弃置一张,弃置的牌不放回牌堆,当手中14张牌两两成对时游戏结束,问结束的期望回合
思路:
预处理dp求期望。因为最终只有7种状态,用dp预处理后,所有询问都是o(1)的复杂度。需要注意的是每次/i时要把i转换成逆元
dp数组:f[剩余卡牌数(<=123)][还差j个对子(<=7)]
状态转移:

代码实现:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
const int mod=1e9+7;
const int N=200,M=15;
typedef long long LL;
typedef pair<LL,LL> PII;
string a;
map<string,int> x;
LL f[N][M];
LL qmi(int a,int b,int p){
LL res=1;
while(b){
if(b&1) res=res*a%p;
a=(LL)a*a%p;
b>>=1;
}
return res;
}
int main(){
int t;
cin>>t;
for(int i=3;i<=123;i++){//dp要在预处理时实现,查询只需要对dp结果查询即可
int inv=qmi(i,mod-2,mod);//求逆元
for(int j=1;j<=7&&3*(2*j-1)<=i;j++){
f[i][j] = 3ll * (2 * j - 1) * inv % mod * (f[i - 1][j - 1] + 1) % mod;
f[i][j] = (f[i][j] + 1ll * (i - 3 * (2 * j - 1)) * inv % mod * (f[i - 1][j] + 1) % mod) % mod;
}
}
for(int qa=1;qa<=t;qa++){
cin>>a;
int cs=7;
for(int i=0;i<26;i+=2){
string y=a.substr(i,2);
x[y]++;
//cout<<y<<endl;
if(x[y]==2) cs--;
}
cout<<"Case #"<<qa<<": "<<f[123][cs]%mod<<endl;
for(int i=0;i<26;i+=2){
string y=a.substr(i,2);
x[y]=0;
}
}
return 0;
}边栏推荐
- Ionic4 Learning Notes 6 -- using native ionic4 components in custom components
- Introduction to nipple music theory and personal perception
- Typora is still the most beautiful and beautiful document editing artifact of yyds in my heart. I believe you will never abandon it
- 使用der格式公钥生成publicKey报错
- 1. Typeof view variable type?
- ["code" power is fully open, and "chapter" shows strength] list of contributors to the task challenge in the first quarter of 2022
- Getaverse, a distant bridge to Web3
- Pytoch's journey 1: linear model
- Principle and application of database
- Type-C PD protocol chip while charging and listening
猜你喜欢

QT - animation frame

Type-C PD protocol chip while charging and listening

狂神redis笔记11

Data analysis of network security competition of national vocational college skills competition digital forensics-a

Today's sleep quality record 79 points

卷积神经网络感受野计算指南
![[wechat applet development] custom tabbar case (custom message 99 + little hearts)](/img/49/354ecb448e91d9e15aaec4922a62e1.png)
[wechat applet development] custom tabbar case (custom message 99 + little hearts)

缺失值处理

MySQL - bufferpool related information

Ionic4 learning notes 8 -- UI component 2 list (no practice, direct excerpt)
随机推荐
core dump
redis 数据类型
Four ways of simple interest mode
Date function format conversion
无关的表进行关联查询及null=null条件
Tree chain partition board
Escape character in JS?
深度学习中Dropout原理解析
middleware
Variable and immutable data types
Inoic4 learning notes 2
1. Typeof view variable type?
狂神redis笔记11
04 distributed resource management system yarn
ETL开发工具Kettle下载安装环境搭建及使用教程
2020年中职组“网络空间安全”赛项浙江省竞赛任务书及答案(Flag)
Principle and application of database
Encapsulate function basedata.js
Eternal Blue ms17-010exp reappears
引发0xC0000005内存违例几种可能原因分析