[JZOJ6244] [NOI2019 analog 2019.7.1] [count] Trominoes

Description

Here Insert Picture Description
n,m<=10000

Solution

Consider violence contour DP, in order to put domino
apparent contour of length N + M
contour is monotonic
1 indicates upward, rightward 0 represents
the N 1, M zeros
only four kinds of discharge domino
four kinds of write transfer, It is

1000 0001
1110 0111
1010 0011
1100 0101

Change over quite a 0 to a 1 and the rear frame 3, an intermediate constant
the same packet-mode 3 is converted into only for 10 adjacent
then it is regarded as the contour, and each discharge rather only 1 × 1 dominoes asked sequence number of the topology
using the Young's Theorem hook matrix
is divided by the number factorial matrix size right down position and the position of each product of
the final number of combinations multiplied by a sequence selected from the group represented by
then we find out about the number of combinations, only one of the n × m factorial
direct calculation can.

Code

#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
typedef long long LL;
const int mo=1000000007;
using namespace std;
int n,m,r,c[3][2],js[33333333];
LL ksm(LL k,LL n)
{
    LL s=1;
    for(;n;n>>=1,k=k*k%mo) if(n&1) s=s*k%mo;
    return s;
}
LL calc(int p)
{
    int n=c[p][0],m=c[p][1];
    LL s=1;
    fo(i,1,n+m-1)
    {
        LL nv=ksm(i,mo-2),ct=max(0,min(m-1,i-1)-max(0,i-n)+1);
        s=s*ksm(nv,ct)%mo;      
    }
    return s;
}
int main()
{
    int t;
    cin>>t;
    int R=33333332;
    js[0]=1;
    fo(i,1,R) js[i]=js[i-1]*(LL)i%mo;
    while(t--)
    {
        cin>>n>>m;
        memset(c,0,sizeof(c));
        fo(i,0,n-1) c[i%3][0]++;        
        fo(i,n,n+m-1) c[i%3][1]++;
        r=max(max(c[0][0]*c[0][1],c[1][0]*c[1][1]),c[2][0]*c[2][1]);
        LL v=1;
        int e=c[0][0]*c[0][1]+c[1][0]*c[1][1]+c[2][0]*c[2][1];
        printf("%lld\n",calc(0)*calc(1)%mo*calc(2)%mo*js[e]%mo);
    }
}

Guess you like

Origin www.cnblogs.com/BAJimH/p/11117098.html