bzoj2560 串珠子

这是一道神子集dp……ref1ref2ref3

#include <iostream>
#include <cstdio>
using namespace std;
int n, c[19][19], g[66005], f[66005];
typedef long long ll;
const int mod=1000000007;
int main(){
	cin>>n;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			scanf("%d", &c[i][j]);
	for(int i=0; i<(1<<n); i++){
		g[i] = 1;
		for(int j=1; j<=n; j++)
			if(i&(1<<(j-1)))
				for(int k=j+1; k<=n; k++)
					if(i&(1<<(k-1)))
						g[i] = (ll)g[i] * (1 + c[j][k]) % mod;
	}
	for(int i=0; i<(1<<n); i++){
		int S=i^(i&-i);
		for(int j=S; j; j=(j-1)&S)
			f[i] = (f[i] + (ll)g[j]*f[i^j]%mod) % mod;
		f[i] = (g[i] - f[i] + mod) % mod;
	}
	cout<<f[(1<<n)-1]<<endl;
	return 0;
}
posted @ 2018-05-28 16:46  poorpool  阅读(115)  评论(0编辑  收藏  举报