当前位置:网站首页>Summer Niuke multi school 1:i chiitoitsu (expectation DP, inverse yuan)
Summer Niuke multi school 1:i chiitoitsu (expectation DP, inverse yuan)
2022-07-24 18:48:00 【Dusk of fools】
Basic question meaning :
altogether 136 card ( Four for each Decor ), Initially, you can give from the deck 13 Cards as hands , And there are no more than two cards in each suit , Touch one card at a time , And then from 14 Discard one of the cards , Discarded cards are not put back on the stack , In the hands of 14 The game ends when cards are paired , Ask the end of the expected round
Ideas :
Preprocessing dp Expect . Because in the end, only 7 States , use dp After pretreatment , All inquiries are o(1) Complexity . It should be noted that every time /i When you do i Convert to inverse element
dp Array :f[ Number of cards remaining (<=123)][ Still bad j A couple (<=7)]
State shift :

Code implementation :
#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 It should be implemented during preprocessing , The query only needs to be on dp Result query is enough
int inv=qmi(i,mod-2,mod);// Inverse element
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;
}边栏推荐
- ETL development tool kettle download installation environment construction and use tutorial
- Wechat applet reverse
- FPGA 20个例程篇:9.DDR3内存颗粒初始化写入并通过RS232读取(上)
- [today in history] July 24: caldera v. Microsoft; Amd announced its acquisition of ATI; Google launches chromecast
- 04 distributed resource management system yarn
- OPENGL学习(二)OPENGL渲染管线
- Convolution neural network receptive field calculation Guide
- Nacos简介和控制台服务安装
- JS to achieve progress steps (small exercise)
- MySQL -- implicit conversion of data type
猜你喜欢

L4l7 load balancing

深度学习中Dropout原理解析

Vsftpd2.3.4-端口渗透 6200 irc_3281_backdoor

微信小程序逆向

Common problems of multithreading and concurrent programming (to be continued)

OPENGL学习(二)OPENGL渲染管线

Attack and defense world novice zone PWN

matplotlib

Why is gradient the fastest changing direction of function

2022杭电多校第二场1009 ShuanQ(数学)
随机推荐
Ionic4 learning notes 10 rotation map of an East Project
Ionic4 learning notes 7 -- UI component 1 (no practice, direct excerpt)
MySQL -- implicit conversion of data type
奶头乐理论介绍及个人感悟
多线程与并发编程常见问题(未完待续)
6. How to add an array in Es5?
Wechat applet reverse
使用der格式公钥生成publicKey报错
Vsftpd2.3.4-端口渗透 6200 irc_3281_backdoor
L4l7 load balancing
Getting started with MySQL database
Mysqlworkbench performance analysis tool -- Performance dashboard
2022暑期杭电多校第一场1012Alice and Bob(博弈论)
Vsftpd2.3.4 port penetration 6200 IRC_ 3281_ backdoor
Cryptography knowledge - Introduction to encryption -1
Make C #
微信小程序逆向
vim相关介绍
JS to achieve progress steps (small exercise)
CF lomsat gelral (heuristic merge)