zoukankan      html  css  js  c++  java
  • 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} ight )ast left ( C_{m}^{3}+C_{m}^{4} ight ))

    AC_Code:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 #define endl '
    '
     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
    ",++cas,ans);
    59     }
    60     return 0;
    61 }
  • 相关阅读:
    AttributeUsage属性
    LINQ基本子句
    js 变动首页参与人数
    C#控件的闪烁问题解决方法总结
    AttributeUsage
    MVC3 js+flash图片滚动
    通过写后台权限领悟到的东西
    删除同辈元素并添加指定元素的类
    JS产生两个数之间的随机数
    Web Service 学习笔记
  • 原文地址:https://www.cnblogs.com/wsy107316/p/13469788.html
Copyright © 2011-2022 走看看