当前位置:网站首页>[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;
}
边栏推荐
- U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程
- Create a virtual machine on VMware (system not installed)
- Serializability of concurrent scheduling
- The American Championship is about to start. Are you ready?
- Three "factions" in the metauniverse
- [Yugong series] go teaching course 003-ide installation and basic use in July 2022
- PyGame practical project: write Snake games with 300 lines of code
- Granularity of blocking of concurrency control
- MySQL disconnection reports an error MySQL ldb_ exceptions. OperationalError 4031, The client was disconnected by the server
- Performance testing of software testing
猜你喜欢
Summary of concurrency control
Index optimization of performance tuning methodology
Common interview questions of redis factory
Server optimization of performance tuning methodology
极狐公司官方澄清声明
Talking about MySQL index
The difference between MVVM and MVC
Huawei cloud modelarts text classification - takeout comments
Business learning of mall order module
Decorator learning 01
随机推荐
Stored procedures and stored functions
Advantages and disadvantages of the "Chris Richardson microservice series" microservice architecture
MySQL actual combat 45 lecture learning (I)
Installation of VMware Workstation
What changes has Web3 brought to the Internet?
What if the files on the USB flash disk cannot be deleted? Win11 unable to delete U disk file solution tutorial
Leetcode simple question ring and rod
Server optimization of performance tuning methodology
数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖
Win11运行cmd提示“请求的操作需要提升”的解决方法
A substring with a length of three and different characters in the leetcode simple question
Oracle checkpoint queue - Analysis of the principle of instance crash recovery
C language knowledge points link
科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖
Oracle advanced query
Database recovery strategy
Reptile practice
微服务入门(RestTemplate、Eureka、Nacos、Feign、Gateway)
How to add new fields to mongodb with code (all)
Evolution of large website architecture and knowledge system