BZOJ 2560: string of beads form inclusion and exclusion pressure DP +

The problem with that urban planning is almost a routine.   

Imperial is a point, then the point at which the enumeration communication block size, and then the remainder of the lightly attached.  

Since we handpicked a point, so we count the number of programs will certainly not be repeated. 

code:

#include <cstdio> 
#include <algorithm>         
#define ll long long 
#define mod 1000000007 
#define setIO(s) freopen(s".in","r",stdin)         
using namespace std; 
int n; 
ll g[67000],f[67000],c[20][20];    
void pre(int S) 
{
    g[S]=1;  
    for(int i=1;i<=n;++i) 
    {
        if((1<<(i-1))&S)          
            for(int j=i+1;j<=n;++j) 
                if((1<<(j-1))&S) (g[S]*=(c[i][j]+1))%=mod;    
    }
}
int main() 
{ 
    // setIO("input"); 
    int i,j;   
    scanf("%d",&n); 
    for(i=1;i<=n;++i) for(j=1;j<=n;++j) scanf("%lld",&c[i][j]);  
    for(i=0;i<(1<<n);++i) pre(i);     
    for(int S=0;S<(1<<n);++S) 
    {
        f[S]=g[S];  
        int i=S^(S&-S);   
        for(int j=i;j;j=(j-1)&i) f[S]=(f[S]-g[j]*f[S^j]%mod+mod)%mod;   
    }  
    printf("%lld\n",f[(1<<n)-1]%mod);    
    return 0;
}

  

Guess you like

Origin www.cnblogs.com/guangheli/p/12157107.html