当前位置:网站首页>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;
}边栏推荐
- 杭电多校第一场第三题 Backpack(异或dp+bitset)
- Mysql——》数据类型隐式转换
- Serial vector format (SVF) file format
- Wechat applet reverse
- Ionic4 learning notes 10 rotation map of an East Project
- 知乎上的那些神回复
- 卷积神经网络感受野计算指南
- Data model subclassing reference
- Namespace: cluster environment sharing and isolation
- Easily learn pytoch transfer learning to realize surface defect inspection
猜你喜欢

C Programming classic tutorial

Ionic4 learning notes 4 -- add a tab page
![[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)

Calling startActivity() from outside of an Activity context requires the FLAG_ ACTIVITY_ NEW_ TASK flag

无关的表进行关联查询及null=null条件

QT—动画框架

理解corners_align,两种看待像素的视角

Today's sleep quality record 79 points

Escape character in JS?
![[today in history] July 24: caldera v. Microsoft; Amd announced its acquisition of ATI; Google launches chromecast](/img/7d/7a01c8c6923077d6c201bf1ae02c8c.png)
[today in history] July 24: caldera v. Microsoft; Amd announced its acquisition of ATI; Google launches chromecast
随机推荐
3. Variable declaration promotion?
理解动态计算图,requires_grad、zero_grad
redis 数据类型
[today in history] July 24: caldera v. Microsoft; Amd announced its acquisition of ATI; Google launches chromecast
今日睡眠质量记录79分
Crazy God redis notes 11
Ionic4 learning notes 5-- custom public module
Serial vector format (SVF) file format
We have to understand the four scopes: application, session, request and page
Why is gradient the fastest changing direction of function
FPGA 20个例程篇:9.DDR3内存颗粒初始化写入并通过RS232读取(下)
Ionic4 learning notes 11 - popular goods display of an East Project
Introduction to nipple music theory and personal perception
字符串的遍历及拼接
Mysql——》BufferPool相关信息
理解corners_align,两种看待像素的视角
投资的新阶段
OPENGL学习(五)Modern OpenGL 三角形绘制
深度学习中Dropout原理解析
Easily learn pytoch transfer learning to realize surface defect inspection