跳到正文

剪贴板

剪贴板 bc5n08nx

CarroT1212
原文
剪贴板信息

剪贴板信息

发布
收录
更新

years C

C++
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mms(x) memset(x,0,sizeof(x))
using namespace std; bool MEM;
using ll=long long; using ld=long double;
using pii=pair<int,int>; using pll=pair<ll,ll>;
const int I=1e9;
const ll J=1e18,N=15,M=507,P=1e9+7;
ll qp(ll x,ll y=P-2) { return y?(y&1?x:1)*qp(x*x%P,y>>1)%P:1; }
ll type,n,m,U,ee[1ll<<N],dp[1ll<<N],p2[M],q2[M],f[1ll<<N],g[1ll<<N],ans;
struct edg { ll x,y,z; } b[M];
ll ce(ll s,ll t) { return ee[s|t]-ee[s]-ee[t]; }
void mian() {
	scanf("%lld%lld",&n,&m),U=(1ll<<n)-1;
	mms(ee),mms(dp),mms(f),mms(g),ans=0;
	for (ll i=0,x,y,z;i<m;i++) scanf("%lld%lld%lld",&x,&y,&z),x--,y--,b[i]={x,y,z};
	for (ll s=0;s<1ll<<n;s++) for (ll i=0;i<m;i++) ee[s]+=s>>b[i].x&1&&s>>b[i].y&1;
	for (ll s=1;s<1ll<<n;s++) {
		f[s]=p2[ee[s]*2];
		for (ll t=s;t;t=(t-1)&s) if (t&(s&-s)) (g[s]+=P-f[t]*g[s^t]%P)%=P;
		for (ll t=s;t;t=(t-1)&s) (f[s]+=P-g[t]*p2[ee[s^t]*2+ce(s^t,t)]%P)%=P;
		(g[s]+=f[s])%=P;
	}
	for (ll s=1;s<1ll<<n;s++) (f[s]*=q2[ee[s]*2])%=P;
	dp[U]=1;
	for (ll s=U;s;s--) if (dp[s])
		for (ll t=(s-1)&s;t;t=(t-1)&s) (dp[s^t]+=dp[s]*(P-q2[ce(s^t,t)]))%=P;
	for (ll i=0;i<n;i++) for (ll s=(1ll<<n)-1;s;s--) if (s>>i&1^1) (dp[s]+=dp[s|1ll<<i])%=P;
	for (ll s=1;s<1ll<<n;s++) (ans+=dp[s]*f[s]%P*q2[ce(s,U^s)])%=P;
	cout<<ans<<"\n";
}
bool ORY; int main() {
	// freopen("years3.in","r",stdin);
	p2[0]=q2[0]=1;
	for (ll i=1;i<M;i++) p2[i]=p2[i-1]*2%P,q2[i]=qp(p2[i]);
	// while (1)
	int t; for (scanf("%lld%d",&type,&t);t--;)
	mian();
	cerr<<"\n"<<abs(&MEM-&ORY)/1048576<<"MB";
	return 0;
}