当前位置:网站首页>The 2021 ICPC ASIA Taipei Regional programming contest L. leadfoot (combinatorics /2-adic assignment function +kummer theorem)
The 2021 ICPC ASIA Taipei Regional programming contest L. leadfoot (combinatorics /2-adic assignment function +kummer theorem)
2022-07-28 17:10:00 【Code92007】
subject
The meaning of this topic depends on the topic
The number of drivers is unknown , Each driver initially wins 0 game , transport 0 game ,
Two drivers who currently win and lose the same number of games , Will play a game together ,
After the competition , The number of games won by one of the drivers +1, The number of games lost by the other driver +1,
The driver thought he won in total n site , Or lose in total m No more games after the game ,
You want to invite the least number of drivers , So that everyone can win in total n site , Or lose altogether m site ,
among , Win. 0 site 、 lost m The driver of the field will be awarded Leadfoot badges,
k(k<=1e5) Group example , Give each time n,m(1<=n,m<=1e5),
How many should be prepared at least for each inquiry Leadfoot badges, The answer is right 1e9+7 modulus
Source of ideas
Official explanation
Answer key
actually , There are enough drivers , The number of people equivalent to any step of the game is an integer ,
The solution to the question mentioned 2-adic valuation/kummer lemma, It sounds high-end , actually ,
2-adic valuation,2- Enter the assignment function , It can be considered as how many a number contains 2 The power of ,
Suppose the last game is to win , Then the front must have won n-1 game , And lost j site (0<=j<m), Consider the order ,C(n-1+j,j)
Suppose the last sentence is to lose , Empathy , The front lost m-1 game , Win. i site (0<=i<n), Consider the order ,C(m-1+i,i)
Suppose the number of drivers is 64( contain 7 individual 2 The power of ), And some final state C(n-1+j,j) The value of contains 3 individual 2 The power of ( Might as well be 8),
Now , The number of drivers is 8, Terminal state C(n-1+j,j) The value of is 1, It is the optimal number of drivers corresponding to this final state ,
According to each final state , Find out the corresponding optimal number of drivers , The biggest one is The actual minimum number of drivers
Find out the minimum number of drivers , Divide 2 Of m Power , That is Continuous transportation m The minimum number of people in the field
actually , according to kummer Theorem ,
C(n+m,m) Include... Under binary 2 The power of , be equal to m+n Carry times of addition under binary ,
2e5 Insufficient binary bits of 20, The number of rounds will not exceed 20, Which contains 2 The power of cannot exceed 20,
therefore , Check only [max(0,i-20),i] and [max(0,j-20),j] that will do
Code
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,mod=1e9+7;
#define dbg(x) cerr<<#x<<":"<<(x)<<endl;
int t,n,m,two[N];
int C(int n,int m){
return two[n]-two[m]-two[n-m];
}
int modpow(int x,int n,int mod){
int res=1;
for(;n;n/=2,x=1ll*x*x%mod){
if(n&1)res=1ll*res*x%mod;
}
return res;
}
int main(){
for(int i=1;i<N;++i){
for(int j=i;j%2==0;j/=2){
two[i]++;
}
two[i]+=two[i-1];
}
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
int ans=0;
for(int i=max(0,n-20);i<n;++i){
for(int j=max(0,m-20);j<m;++j){
ans=max(ans,1+i+j-C(i+j,i));
}
}
//dbg(ans);
printf("%d\n",modpow(2,ans-m,mod));
}
return 0;
}边栏推荐
- Rsync service deployment and parameter details
- Alibaba cloud MSE supports go language traffic protection
- Record development issues
- [deep learning]: introduction to pytorch to project practice: simple code to realize linear neural network (with code)
- Best cow fences solution
- A total of 13billion flash and 400million MCU were shipped! In depth analysis of the three product lines of Zhaoyi innovation
- Function接口之andThen
- Unity shader cartoon style rendering
- Unity shader transparent effect
- 做题笔记5(有序数组的平方)
猜你喜欢

Ugui learning notes (II) Scrollview related

MySQL 5.7 and sqlyogv12 installation and use cracking and common commands

Games101-assignment05 ray tracing - rays intersect triangles

Ruoyi's solution to error reporting after integrating flyway

综合设计一个OPPE主页--页面服务部分

Egg (19): use egg redis performance optimization to cache data and improve response efficiency

负整数及浮点数的二进制表示

Atcoder regular contest 133 d.range XOR (digital dp+ classification discussion)

在AD中添加差分对及连线

【深度学习】:《PyTorch入门到项目实战》第五天:从0到1实现Softmax回归(含源码)
随机推荐
记录开发问题
Question making note 2 (add two numbers)
Ruoyi集成flyway后启动报错的解决方法
Technology sharing | MySQL shell customized deployment MySQL instance
Record the processing process of CEPH two RBDS that cannot be deleted
[JS] eight practical new functions of 1394-es2022
向高通支付18亿美元专利费之后,传华为向联发科订购了1.2亿颗芯片!官方回应
Unity shader depth of field effect
综合设计一个OPPE主页--页面的售后服务
Unity shader transparent effect
Question making note 3 (two point search)
Unity editor learning (I) using features to change the display of fields in components
Epoll horizontal departure, which edge triggers
Deep understanding of deepsea and salt deployment tools – storage6
Understanding of asmlinkage
Semtech launched Lora edge, a geolocation solution for the Internet of things, and the first chip lr1110 is now on the market
[deep learning]: day 1 of pytorch introduction to project practice: data operation and automatic derivation
[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)
epoll水平出发何边沿触发
Unity shader cartoon style rendering