hdu4779 Combination Count +DP

Source: Internet
Author: User

Submit

Test instructions: Given the n*m grid, then a P-heavy defense tower, capable of withstanding 1 attacks, q a light tower can not accept any attack, then each defense will attack his row and the column, and finally to put at least one defense tower on this grid program number,

We enumerate how many heavy defense towers are selected and how much of this heavy defense tower is two in one row, and two in a row O (p^3) efficiency

#include <iostream>#include<algorithm>#include<cstdio>#include<string.h>#include<vector>using namespaceStd;typedefLong LongLL;ConstLL mod=1000000007;Const intmaxn=202; LL C[MAXN][MAXN];//Number of combinationsLL LIGHT[MAXN][MAXN][MAXN];//light[i][j][k]k stack Lightweight defense tower put in the I row J column of the Matrix scheme numberLL HEAVY[MAXN];//Haeavy[i] Represents the number of programs with a weight of two of the same rowLL NT[MAXN];//n! N factorialvoidinit () {nt[0]=1;  for(LL i=1; i<= $; i++) Nt[i]= (nt[i-1]*i)%MOD; memset (C,0,sizeof(C)); c[0][0]=1;  for(intI=1; i<= $; i++) {c[i][0]=1;  for(intj=1; j<=i; J + +) C[i][j]= (c[i-1][j]+c[i-1][j-1])%MOD; }     for(intI=1; i<= $; i++)         for(intj=1; j<= $; J + +)        {             intkm=min (i,j); light[I [j] [0] =1;  for(intk=1; k<=km; k++) {light[i] [j] [K]= ((((c[i] [k]*c[J] [K])%mod) *nt[k])%MOD; }        }     for(intI=1; i<= $; i++)         for(intj=1; j<= $; J + +)        {             intkm=min (i,j);  for(intk=1; k<=km; k++) Light[i][j][k]= (light[i][j][k-1]+LIGHT[I][J][K])%MOD; } heavy[0]=1;  for(intI=1; i<= -; i++) {LL ans=1;  for(intj=i*2; J>2; j-=2) {ans= (c[j][2]*ans)%MOD; } Heavy[i]=ans; }}intMain () {init (); intn,m,p,q; intCAs; scanf ("%d",&CAs);  for(intCc=1; cc<=cas; Cc++) {scanf ("%d%d%d%d",&n,&m,&p,&Q); LL ans=0;  for(intk=1; k<=p; k++)             for(intI=0; i<=k; i+=2)               for(intj=0; j+i<=k; j+=2)              {                 intln=n-i/2-J; intlm=m-j/2-i; if(min (LN,LM) <k-(i+j))Continue; LN=n,lm=l; LL D=1; D= (((c[ln][i/2]*c[lm][i]%mod) *heavy[i/2])%MOD; LN-=i/2; lm-=i; D= (d* (((c[ln][j) * c[lm][j/2])%mod) * heavy[j/2]) (%MOD))%MOD; LN-=J; LM-=j/2; intlest=k-(i+j); D= ((((D* ((c[ln][lest]*c[lm][lest)%mod)%mod) *nt[lest])%MOD; LN-=lest; lm-=lest; if(ln>0&&LM>0)                 {                     intGe=min (min (ln,lm), Q); D= (d* (light[ln][lm][ge))%MOD; } ans= (ans+d)%MOD; }        if(q>0)        {            intGe=min (min (n,m), Q); Ans= (Ans+light[n][m][ge])%MOD; Ans= (ans-1+MOD)%MOD; } printf ("%i64d\n", ans%MOD); }    return 0;}
View Code

hdu4779 combined Count +DP

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.