跳到正文

题解

题解:CF2120D Matrix game

_O_v_O_约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年6月27日
收录
2025年12月12日
更新
2026年11月9日
篇幅
约 2 分钟
获赞
8
题目
CF2120D

版本

  1. v1当前

赛时唐了,看到组合数不会算了。

先考虑 nn。

根据鸽笼原理,每列中至少应有一种数出现 aa 次。

那么很显然,nn 最少为 k×(a−1)+1k\times(a-1)+1。

再考虑 mm。

设 xx 为每列中能出现的不同方案数,很显然 x=(na)×kx={n\choose a}\times k。这个组合是可以暴力算的。

根据鸽笼原理,这个矩阵中最少要有一种方案出现了 bb 次,那么 m=x×(b−1)+1m=x\times (b-1)+1。

code:

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long

const int mod=1e9+7;
int a,b,k;
int n,m; 

int fp(int a,int b){
	int ans=1;
	while(b){
		if(b&1) (ans*=a)%=mod;
		(a*=a)%=mod;
		b>>=1;
	}
	return ans;
} 
int inv(int x){
	return fp(x,mod-2)%mod;
}

int calc(int x,int y){
	int res=1;
	for(int i=1;i<=y;i++) (res*=inv(i)*((n-i+1+mod))%mod)%=mod;
	return res;
}

signed main(){
	ios::sync_with_stdio(0),cin.tie(0);
	int T;cin>>T;while(T--){
		cin>>a>>b>>k;
		n=(a-1)*k+1;n%=mod;
		m=calc(n,a);m=m*k%mod*(b-1)%mod+1;m%=mod;
		cout<<n<<' '<<m<<endl;
	}
	return 0;
}
原文
存档评论2 条抓取于