E. Another Filling the Grid 状压dp

  http://codeforces.com/contest/1228/my

 

 

 

 The meaning of problems: There nm each rectangular grid may take a digital 1-k is asked how many fill methods per row such that at least 1 has a

 

Solution: Set dp [i] [j] indicates that the current process to the i-th row j as there are a number of protocol 1 and contribute to the statistical answer attention diverted at least take a 1

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define see(x) (cerr<<(#x)<<'='<<(x)<<endl)
#define inf 0x3f3f3f3f
#define CLR(A,v)  memset(A,v,sizeof A)
//////////////////////////////////
const int N=300;
const ll mod=1e9+7;
ll dp[N][N],mi[N],mi_1[N],C[N][N],n,k;
int main()
{
    cin>>n>>k;
    rep(i,0,n)
    {
        C[i][0]=1;
        rep(j,1,i)C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
    }
    mi[0]=mi_1[0]=1;
    rep(i,1,n)mi[i]=mi[i-1]*k%mod,mi_1[i]=mi_1[i-1]*(k-1)%mod;
    rep(i,1,n)dp[1][i]=C[n][i]*mi_1[n-i]%mod;
    rep(i,2,n)rep(j,0 , n-) REP (S, 0 , J) 
    { 
      DP [I] [J] = (DP [I] [J] + DP [I- . 1 ] [S] * C [NS] [JS] *% MOD mi The [S] *% MOD mi_1 [NJ]% MOD)% MOD;
       IF (J == S) DP [I] [J] = (DP [I] [J] -mi_1 [n-] * DP [I- . 1 ] [S] + MOD% MOD) MOD%; // must be off all inclusion and exclusion of a number of non-program 
    } 
    COUT << DP [n-] [n-];
     return  0 ; 
}
View Code

 

Guess you like

Origin www.cnblogs.com/bxd123/p/11618291.html