当前位置:网站首页>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;
}
/* */
边栏推荐
- Is low code the future of development? On low code platform
- TP5 -- query field contains a certain --find of search criteria_ IN_ SET
- 【论文阅读】Transformer with Transfer CNN for Remote-Sensing-ImageObject Detection
- The whereor method of TP5 has many conditions
- The method of inserting degree in word
- Cubemx联合IAR工程移植
- How PHP changes a two-dimensional array into a one-dimensional array
- Notes on implementation and acquisition of flowable custom attributes
- OpenCV(一)——图像基础知识
- The 31st --- the 52nd
猜你喜欢

Cron expression use

Opencv (V) -- moving target recognition

201403-1

The new JMeter function assistant is not under the options menu - in the toolbar

2021 national vocational college skills competition (secondary vocational group) network security competition questions (9) ideas

201403-1

Matlab legend usage

DRF learning notes (II): Data deserialization

Leetcode25 question: turn the linked list in a group of K -- detailed explanation of the difficult questions of the linked list

Reduce PDF document size (Reprint)
随机推荐
Yys mouse connector
Flume incrementally collects MySQL data to Kafka
t5 学习
Product axure9 English version, using repeater repeater to realize drop-down multi selection box
Chuanyin holdings disclosed that it was prosecuted by Huawei: a case has been filed, involving an amount of 20million yuan
word中插入度的方法
Mazak handwheel maintenance Mazak little giant CNC machine tool handle operator maintenance av-eahs-382-1
What is ti's calculation for successively canceling the agency rights of anfuli / Wenye / Shiping?
DRF learning notes (IV): DRF view
Rotate string left
solidwork装配体导入到Adams中出现多个Part重名和Part丢失的情况处理
mvc和mvp和mvvm的区别
Use of arrow function
Test novice learning classic (with ideas)
2021 national vocational college skills competition (secondary vocational group) network security competition questions (9) ideas
Leetcode 226 flip binary tree (recursive)
TP5 -- query field contains a certain --find of search criteria_ IN_ SET
CCF-201312-1
【pytorch】|transforms.FiveCrop
重新配置cubemx后,生成的代码用IAR打开不成功