当前位置:网站首页>Great Cells & Counting Grids
Great Cells & Counting Grids
2022-07-27 16:39:00 【dplovetree】
101194 H Great Cells
The question :
If a lattice in a matrix satisfies that it is strictly greater than all the other numbers of its rows and columns , Then we call this lattice Great Cells, A g A_{g} Ag The representative happens to have g g g individual Great Cells When the number of programs . Give a n n n That's ok m m m Matrix and a number of columns k k k, k k k Indicates that each grid can be selected from [ 1 , k ] [1,k] [1,k] Select a number from the list and put it into the current grid .( N , M , K < = 200 N,M,K<=200 N,M,K<=200)
To calculate the result of this formula :
∑ g = 0 N M ( g + 1 ) ⋅ A g m o d ( 1 e 9 + 7 ) \sum_{g=0}^{NM}{(g+1) ·A_g}\mod{(1e9+7)} g=0∑NM(g+1)⋅Agmod(1e9+7)
Ideas :
Deform the required formula appropriately to get :
∑ g = 0 N M g ⋅ A g m o d ( 1 e 9 + 7 ) + ∑ g = 0 N M A g m o d ( 1 e 9 + 7 ) \sum_{g=0}^{NM}{g ·A_g}\mod{(1e9+7)}+ \sum_{g=0}^{NM}{A_g}\mod{(1e9+7)} g=0∑NMg⋅Agmod(1e9+7)+g=0∑NMAgmod(1e9+7)
It is not difficult to find that the formula on the right is to sum all the schemes , So for K N M K^{NM} KNM;
Next, look at the formula on the left , For a particular one g g g individual Great Cells The plan , The contribution to the overall answer is g g g, It can be seen as every Great Cells All contribute to the total answer 1; So the formula on the left can be seen as , For all grids as Great Cells Sum of cases .
Then just for each grid , Find out what he does Great Cells The number of schemes is enough , Just satisfy that it is a peer 、 The maximum value in the same column , You can enumerate the values of this lattice , Come and make peace :
N M ∑ i = 1 K ( i − 1 ) N + M − 2 ⋅ K N M − N − M + 1 NM\sum_{i=1}^{K}{(i-1)^{N+M-2}·K^{NM-N-M+1}} NMi=1∑K(i−1)N+M−2⋅KNM−N−M+1
Finally, add K N M K^{NM} KNM that will do ;
Code :
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
const ll mod=1e9+7;
int t,n;
ll qp(ll x,ll n){
ll ans=1;
while(n){
if(n&1)ans=ans*x%mod;
x=x*x%mod;
n/=2;
}
return ans;
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>t;
int T=0;
while(t--){
T++;
int n,m,k;
cin>>n>>m>>k;
ll ans=qp(k,n*m);
ll res=0;
for(int i=1;i<k;i++){
res=(res+qp(i,n-1+m-1)*qp(k,n*m-n-m+1)%mod)%mod;
}
res=res*n*m%mod;
ans=(ans+res)%mod;
cout<<"Case #"<<T<<": "<<ans<<'\n';
}
return 0;
}
/* */
ARC143 B Counting Grids
The question :
Seek to use 1 1 1 To N 2 N^2 N2 fill N ∗ N N*N N∗N How many schemes does the matrix have , There is no point of satisfaction , It is both the maximum value of the same column and the minimum value of the same row .
Ideas :
We weigh a point , If it is both the maximum value of the same column and the minimum value of the same row , So it's a bad point ;
Then you need to ask The number of schemes without bad points , It's not hard to think of using tolerance and exclusion :
hypothesis a i , j a_{i,j} ai,j Express ( i , j ) (i,j) (i,j) This point is bad ;
In fact, we need to ask
∣ S − a 1 , 1 ∪ a 1 , 2 ∪ . . . ∪ a n , n ∣ |S-a_{1,1}\cup a_{1,2}\cup ...\cup a_{n,n}| ∣S−a1,1∪a1,2∪...∪an,n∣
Expand with the principle of inclusion and exclusion , hypothesis f ( i ) f(i) f(i) For at least i i i The number of schemes where a point is a bad point :
= ∣ S ∣ − C N ∗ N 1 ⋅ f ( 1 ) + C N ∗ N 2 ⋅ f ( 2 ) − . . . . C N ∗ N N ∗ N ⋅ f ( N ∗ N ) =|S|-C_{N*N}^{1}·f(1)+C_{N*N}^{2}·f(2)-....C_{N*N}^{N*N}·f(N*N) =∣S∣−CN∗N1⋅f(1)+CN∗N2⋅f(2)−....CN∗NN∗N⋅f(N∗N)
If we ask f ( i ) f(i) f(i) Words , For each f ( i ) f(i) f(i), I can only think of highly complex d p dp dp How to find , The complexity is definitely unbearable .
But this topic also has a wonderful property : It is impossible to have more than one bad point , Prove the following :
hypothesis a , d a,d a,d For the bad , Then according to the definition of bad points , You can get the following relation :
a > c a>c a>c、 a < b a<b a<b、 d > b d>b d>b、 d < c d<c d<c ;
Put it in order : a < b < d a<b<d a<b<d、 a > c > d a>c>d a>c>d ;
It's obviously a conflict , that ∀ x ∈ [ 2 , N ∗ N ] , f ( x ) = 0 \forall{x \in [2,N*N]},{f(x)=0} ∀x∈[2,N∗N],f(x)=0 ;
Then the original formula becomes :
= ∣ S ∣ − C N ∗ N 1 ⋅ f ( 1 ) =|S|-C_{N*N}^{1}·f(1) =∣S∣−CN∗N1⋅f(1)
Easy to get : ∣ S ∣ = ( N ∗ N ) ! |S|=(N*N)! ∣S∣=(N∗N)!
Then you need to ask f ( 1 ) f(1) f(1), It only needs to satisfy that there is a point satisfying that it is the maximum value of the same column , At the same time, it is also the minimum value of peers , It's not hard to figure out :
f ( 1 ) = N ∗ N ∗ C N 2 2 N − 1 ⋅ ( N − 1 ) ! ( N − 1 ) ! ( N ∗ N − 2 N + 1 ) ! f(1)=N*N*C_{N^2}^{2N-1}·(N-1)!(N-1)!(N*N-2N+1)! f(1)=N∗N∗CN22N−1⋅(N−1)!(N−1)!(N∗N−2N+1)!
Code :
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
const ll mod=998244353;
int t,n;
ll qp(ll x,ll n){
ll ans=1;
while(n){
if(n&1)ans=ans*x%mod;
x=x*x%mod;
n/=2;
}
return ans;
}
ll jie[250005];
ll inv[250005];
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n;
ll ans=0;
jie[0]=1;
for(int i=1;i<=n*n;i++)jie[i]=jie[i-1]*i%mod;
inv[n*n]=qp(jie[n*n],mod-2);
for(int i=n*n;i>=1;i--)inv[i-1]=inv[i]*i%mod;
ans=n*n*jie[n*n]%mod*inv[n*n-2*n+1]%mod*inv[2*n-1]%mod*jie[n-1]%mod*jie[n-1]%mod*jie[n*n-2*n+1]%mod;
ans=(jie[n*n]-ans+mod)%mod;
cout<<ans<<'\n';
return 0;
}
/* */
边栏推荐
- 201403-1
- Leetcode 226 flip binary tree (recursive)
- 【论文阅读】A CNN-transformer hybrid approach for decoding visual neuralactivity into text
- mvc和mvp和mvvm的区别
- The class declared by the scala object keyword directly calls methods and associated objects
- CCF-201312-1
- The method of inserting degree in word
- Time series ARIMA model
- Flume incrementally collects MySQL data to Kafka
- 字节跳动服务网格基于 Hertz 框架的落地实践
猜你喜欢

MySQL high version report SQL_ mode=only_ full_ group_ By exception

my_ Ls summary

Exe program encryption lock

减小PDF文档大小(转载)

The difference and use between get request and post request

Implementation of ByteDance service grid based on Hertz framework

Jupyter creates a virtual environment and installs pytorch (GPU)

Opencv (IV) -- image features and target detection

OpenCV(四)——图像特征与目标检测

Cron expression use
随机推荐
Google Chrome reversecaptcha ad blocking
Log management
CCF-201312-1
【论文阅读】A CNN-transformer hybrid approach for decoding visual neuralactivity into text
excel skill
The difference and use between get request and post request
Is low code the future of development? On low code platform
Example of the task submitted by the Flink packer
Chapter I Marxist philosophy is a scientific world outlook and methodology
google chrome revercecaptcha广告屏蔽
Opencv (I) -- basic knowledge of image
Install MySQL using CentOS yum
插入word中的图片保持高dpi方法
The whereor method of TP5 has many conditions
C语言逆序输出字符串
const小结
Boolean value
Embedded interview
2021-03-09
The class declared by the scala object keyword directly calls methods and associated objects