Pastoral Life in Stardew Valley

Pastoral Life in Stardew Valley

题意:给定一个\(n*m\)大小的矩阵,在里面画两个矩阵,且两个矩阵嵌套。小矩阵最小为\(1*1\)。求有多少种方案

题解:对于矩形,由于长宽互不影响,所以我们根据乘法原理先算横坐标有多少种情况,纵坐标有多少种情况,最后相乘就好了

看横坐标:

  • 小区间的长度的等于1时,那么就相当于长度为n的一排格子,选3个格子,就是\(C_{n}^{3}\)
  • 小区间长度大于1时,那么相当于长度为n的一排格子,选4个格子,就是\(C_{n}^{4}\)

纵坐标同理,所以整体答案为:\(\left ( C_{n}^{3}+C_{n}^{4}\right )\ast \left ( C_{m}^{3}+C_{m}^{4}\right )\)

AC_Code:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 #define endl '\n'
 5 const int mod=1e9+7;
 6 const int maxn=1e5+10;
 7 
 8 
 9 ll n,m,ans;
10 ll a[maxn];
11 
12 ll qpow(ll a,ll b){
13     ll res=1;
14     while(b){
15         if( b&1 ) res=res*a%mod;
16         a=a*a%mod;
17         b>>=1;
18     }
19     return res;
20 }
21 
22 void init(){
23     a[1]=1;
24     for(int i=2;i<=100000;i++){
25         a[i]=a[i-1]*i;
26         a[i]%=mod;
27     }
28 }
29 
30 ll C_3(ll x){
31     if( x<3 ) return 0;
32     if( x==3 ) return 1;
33     ll res=a[x];
34     res=a[x]*qpow(6,mod-2)%mod;
35     res=res*qpow(a[x-3], mod-2)%mod;
36     return res;
37 }
38 
39 ll C_4(ll x){
40     if( x<4 ) return 0;
41     if( x==4 ) return 1;
42     ll res=a[x];
43     res=a[x]*qpow(24,mod-2)%mod;
44     res=res*qpow(a[x-4],mod-2)%mod;
45     return res;
46 }
47 
48 int main()
49 {
50     int t,cas=0; scanf("%d",&t);
51     init();
52     while( t-- ){
53         ll ans;
54         scanf("%lld%lld",&n,&m);
55         ll ans1=(C_3(n)+C_4(n))%mod;
56         ll ans2=(C_3(m)+C_4(m))%mod;
57         ans=ans1*ans2%mod;
58         printf("Case %d: %lld\n",++cas,ans);
59     }
60     return 0;
61 }

 

posted @ 2020-08-10 14:57  swsyya  阅读(267)  评论(0编辑  收藏  举报

回到顶部