TC Srm 597 Div 1 T3

Source: Internet
Author: User

Test instructions

Give M,r,g,b,2m=r+b+g,m represents a 2*m area of the number of columns, RGB Code Red Green and blue lattice number, requirements: Each 2*2 lattice, three colors each has at least one lattice, and the adjacent lattice color is different, ask how many kinds of arrangement

First we find that we can divide a two-grid placement scheme into two groups, {RB,BG,GR},{BR,GB,RG}

A legitimate scheme must consist of only one group, so we can calculate a set of scenarios and then x2 it

So we assume that RB has X, BG has y, GR has z, then ans is equivalent to: the number of placement schemes that make BR,RG,GB separate from itself.

Let's assume x>y>z, first we're going to use y,z to fill the gap between X,

If y+z<x-1, it cannot be filled, returns 0

Otherwise, we have 4 kinds of programs, fill in the middle x-1, X on the left, X on the right, all x+1, we can calculate the x-1~x+1 respectively

So now there's NX (nx=x+1/x/x-1) empty, we're going to fill it with y,z,

1. First of all, we assume that the Y1 is filled with Y, the scheme is C (nx,y-1), filled with Z z1=x-y1 empty

2. More y2=y-y1, the scheme of Y2 is equivalent to dividing all y into y1 parts, C (y-1,y1-1)

For each of the multi-plug y, we fortress a Z to prevent y adjacent, then after the end of our z is z2=z-z1-y2, and then insert these z y1 sequence of two ends, the scheme is C (2*Y1,Z2)

At this point, the assignment ends

#include <cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<cstring>using namespaceStd;typedefLong Longll;intn=1000000;intmo=1000000007;intjc[1000011],fc[1000011];intans,tmp,ts,x,y,z,xl,yl,req,zl,dt,tj,m,r,g,b,j,i;intMiintXintz) {    intl; L=1;  while(z) {if(z%2==1) l= (LL) l*x%mo; X= (LL) x*x%mo; Z/=2; }    returnl;}intCintNintm) {    return(LL) jc[n]*fc[m]%mo*fc[n-m]%mo;}intMain () {jc[0]=1;  for(i=1; i<=n;i++) jc[i]= (LL) jc[i-1]*i%mo; Fc[n]=mi (jc[n],mo-2);  for(i=n-1; i>=0; i--) fc[i]= (LL) fc[i+1]* (i+1)%mo; scanf ("%d",&DT);  for(tj=1; tj<=dt;tj++) {scanf ("%d%d%d%d",&m,&r,&g,&B); X=m-b;y=m-r;z=m-G; if(x<0|| y<0|| z<0) {printf ("0\n"); Continue; } ans=0; if(y>×) swap (x, y); if(z>x) swap (X,Z); if(z>y) Swap (y,z); if(y+z<x-1) {printf ("0\n"); Continue; }         for(xl=x-1; xl<=x+1; xl++){            if(Y+Z&LT;XL)Continue; TMP=0;  for(j=1; j<=y;j++) {req=xl-J; if(req>z)Continue; YL=y-K; if(req+yl>z)Continue; TS=C (XL,J); TS= (ll) ts*c (y1, J-1)%mo; ZL=z-req-yl; if(zl>2*J)Continue; TS= (ll) ts*c (2*J,ZL)%mo; TMP= (tmp+ts)%mo; }            if(xl==x) tmp=tmp*2%mo; Ans= (ans+tmp)%mo; } ans= (ans*2)%mo; printf ("%d\n", ans); }}

TC Srm 597 Div 1 T3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.