当前位置:网站首页>[agc009e] eternal average - conclusion, DP
[agc009e] eternal average - conclusion, DP
2022-07-05 22:11:00 【Ouye xjx】
[AGC009E] Eternal Average
Title Description
It's on the blackboard n n n individual 0 and m m m individual 1, Every time we choose k k k Erase it with a number , Then write their average , Do this until there is only one number left , Ask how many different situations there are for the remaining number .
The answer is right 1 0 9 + 7 10^9+7 109+7 modulus
1 ≤ n , m ≤ 2000 , 2 ≤ k ≤ 2000 1 \leq n,m \leq 2000,2 \leq k \leq 2000 1≤n,m≤2000,2≤k≤2000
Guarantee n + m − 1 n+m-1 n+m−1 Can be k − 1 k-1 k−1 to be divisible by .
Answer key
I am a *. It's one step away from the positive solution , I ** Don't push your dead brain . I am a *.
First of all, it's easy to see , The answer must be for everyone 1 and 0 Go with a k − x k^{-x} k−x Add up the coefficients of , Satisfy ∑ k − x i = 1 \sum k^{-x_i}=1 ∑k−xi=1, seek Z = ∑ a i = 1 k − x i Z=\sum_{a_i=1}k^{-x_i} Z=∑ai=1k−xi How many values are there .
Obviously, it needs to be considered in turn k k k Base Z Z Z The value of each decimal place of . set up Z = 0. z 1 z 2 . . . z p , z p > 0 Z=0.z_1z_2...z_p,z_p>0 Z=0.z1z2...zp,zp>0, hypothesis ∑ a i = 1 k − x i \sum_{a_i=1}k^{-x_i} ∑ai=1k−xi There is no carry in the process of summing from low to high , So it must be satisfied ∑ z i = n \sum z_i=n ∑zi=n, If you consider rounding , So satisfied ∑ z i ≤ n \sum z_i\le n ∑zi≤n. however ∑ z i \sum z_i ∑zi Or every one of them z i z_i zi What are the specific restrictions ? If you look stupid * When I arrived here, I didn't continue to deduce, but thought about optimizing violence DP Words , Then you will eventually find yourself to the fourth and fifth power DP How can the plan collapse when it is heavy .( Someone wants to set when pulling this question n , m , k ≤ 10 n,m,k\le 10 n,m,k≤10 Part of , It's really too dare to chip )
In fact, we can easily find , When a carry occurs , Decrease at the low position x ∗ k x*k x∗k , The high position will increase x x x, here ∑ z i \sum z_i ∑zi Just reduced k − 1 k-1 k−1 Integer multiple , in other words ∑ z i \sum z_i ∑zi Still satisfied ∑ z i = n ( m o d k − 1 ) \sum z_i=n(\bmod k-1) ∑zi=n(modk−1). Inductive verification findings , ∑ z i ≤ n \sum z_i\le n ∑zi≤n and ∑ z i = n ( m o d k − 1 ) \sum z_i=n(\bmod k-1) ∑zi=n(modk−1) These two restrictions are enough .
There is still left ∑ k − x i = 1 \sum k^{-x_i}=1 ∑k−xi=1 This condition , We can find that it is actually equivalent to ∑ a i = 0 k − x i = 1 − Z \sum_{a_i=0}k^{-x_i}=1-Z ∑ai=0k−xi=1−Z, We put 1 − Z = 0. ( k − 1 − z 1 ) ( k − 1 − z 2 ) . . . ( k − 1 − z p − 1 ) ( k − z p ) 1-Z=0.(k-1-z_1)(k-1-z_2)...(k-1-z_{p-1})(k-z_p) 1−Z=0.(k−1−z1)(k−1−z2)...(k−1−zp−1)(k−zp) Apply the above derivation to get 1 + ( k − 1 ) p − ∑ z i ≤ m 1+(k-1)p-\sum z_i\le m 1+(k−1)p−∑zi≤m and 1 + ( k − 1 ) p − ∑ z i = m ( m o d k − 1 ) 1+(k-1)p-\sum z_i=m(\bmod k-1) 1+(k−1)p−∑zi=m(modk−1) The limitation of .
then DP The transfer of is obvious , Just set d p [ i ] [ j ] [ 0 / 1 ] dp[i][j][0/1] dp[i][j][0/1] It means taking into account the i i i position , ∑ x = 1 i z x = j \sum_{x=1}^i z_x=j ∑x=1izx=j And z i z_i zi be equal to / Greater than 0 The number of values when , The transfer equation is
d p [ i ] [ j ] [ 0 ] = d p [ i − 1 ] [ j ] [ 0 ] + d p [ i − 1 ] [ j ] [ 1 ] d p [ i ] [ j ] [ 1 ] = ∑ x = 1 k − 1 ( d p [ i − 1 ] [ j − x ] [ 0 ] + d p [ i − 1 ] [ j − x ] [ 1 ] ) dp[i][j][0]=dp[i-1][j][0]+dp[i-1][j][1]\\ dp[i][j][1]=\sum_{x=1}^{k-1}(\,dp[i-1][j-x][0]+dp[i-1][j-x][1]\,) dp[i][j][0]=dp[i−1][j][0]+dp[i−1][j][1]dp[i][j][1]=x=1∑k−1(dp[i−1][j−x][0]+dp[i−1][j−x][1])
And then it's done . No prefixes and optimizations are required , Because the first dimension does not exceed the total operands , Therefore, the direct transfer complexity is O ( n + m − 1 k − 1 k n ) = O ( n 2 ) O(\frac{n+m-1}{k-1}kn)=O(n^2) O(k−1n+m−1kn)=O(n2).
Code
#include<bits/stdc++.h>//JZM yyds!!
#define ll long long
#define uns unsigned
#define IF (it->first)
#define IS (it->second)
#define END putchar('\n')
using namespace std;
const int MAXN=4005;
const ll INF=1e18;
inline ll read(){
ll x=0;bool f=1;char s=getchar();
while((s<'0'||s>'9')&&s>0){
if(s=='-')f^=1;s=getchar();}
while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+(s^48),s=getchar();
return f?x:-x;
}
int ptf[50],lpt;
inline void print(ll x,char c='\n'){
if(x<0)putchar('-'),x=-x;
ptf[lpt=1]=x%10;
while(x>9)x/=10,ptf[++lpt]=x%10;
while(lpt)putchar(ptf[lpt--]^48);
if(c>0)putchar(c);
}
inline ll lowbit(ll x){
return x&-x;}
const ll MOD=1e9+7;
int n,m,k,p;
ll dp[MAXN][MAXN][2],ans;
inline void ad(ll&a,ll b){
a+=b;if(a>=MOD)a-=MOD;}
signed main()
{
n=read(),m=read(),k=read(),p=(n+m-1)/(k-1);
dp[0][0][0]=1;
for(int i=1;i<=p;i++){
for(int j=0;j<=n;j++){
dp[i][j][0]=(dp[i-1][j][0]+dp[i-1][j][1])%MOD;
for(int x=1;x<k&&x<=j;x++)
ad(dp[i][j][1],dp[i-1][j-x][1]),
ad(dp[i][j][1],dp[i-1][j-x][0]);
}
for(int j=0;j<=n;j++)
if(j%(k-1)==n%(k-1)&&((k-1)*i+1-j)<=m&&((k-1)*i+1-j)%(k-1)==m%(k-1))
ad(ans,dp[i][j][1]);
}
print(ans);
return 0;
}
边栏推荐
- A long's perception
- Learning of mall permission module
- Huawei cloud modelarts text classification - takeout comments
- 科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖
- AD637使用笔记
- Code bug correction, char is converted to int high-order symbol extension, resulting in changes in positivity and negativity and values. Int num = (int) (unsigned int) a, which will occur in older com
- Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
- ICMP introduction
- Sentinel production environment practice (I)
- Draw a red lantern with MATLAB
猜你喜欢
元宇宙中的三大“派系”
The American Championship is about to start. Are you ready?
Implementation technology of recovery
Advantages and disadvantages of the "Chris Richardson microservice series" microservice architecture
Matlab | app designer · I used Matlab to make a real-time editor of latex formula
The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
Stored procedures and stored functions
What if win11 is missing a DLL file? Win11 system cannot find DLL file repair method
Huawei game multimedia service calls the method of shielding the voice of the specified player, and the error code 3010 is returned
装饰器学习01
随机推荐
Oracle views the data size of a table
多家呼吸机巨头产品近期被一级召回 呼吸机市场仍在增量竞争
The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!
Comment développer un plug - in d'applet
poj 3237 Tree(樹鏈拆分)
Draw a red lantern with MATLAB
阿龙的感悟
Web3为互联网带来了哪些改变?
The difference between MVVM and MVC
Shell script, awk uses if, for process control
Overview of database recovery
The American Championship is about to start. Are you ready?
Analyse des risques liés aux liaisons de microservices
Interview questions for famous enterprises: Coins represent a given value
MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
DataGrid directly edits and saves "design defects"
How to add new fields to mongodb with code (all)
Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~
微服务链路风险分析
【愚公系列】2022年7月 Go教学课程 004-Go代码注释