| Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
|---|---|---|---|---|---|---|---|---|---|
| 38948 | baka24 | 【BJ】T3 | C++ | 运行超时 | 94 | 1990 MS | 62952 KB | 1398 | 2025-11-19 20:37:51 |
#include<bits/stdc++.h> using namespace std; #define ll long long #define LD long double #define lb(x) ((x)&(-x)) #define popcnt __builtin_popcountll #define hb __lg bool AAA; int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();return x*f;} const int MAXN=100010,N=26,Mod=1e9+7; void add(int &x,int y){x+=y;if(x>=Mod)x-=Mod;}int ad(int x,int y){return x+y>=Mod?x+y-Mod:x+y;} int n,m,ans,x[MAXN],y[MAXN],w[MAXN],jc[MAXN]; ll d[MAXN]; unordered_map<int,int>f[N]; int dfs(ll s,int x){ if(!x)return 1; if(x>popcnt(s))return 0; if(s<(1<<N)&&f[x-1].count(s))return f[x-1][s]; int i=hb(s); int tmp=ad(dfs(s^(1ll<<i),x),(ll)w[i]*dfs((s^d[i])&s,x-1)%Mod); if(s<(1<<N))f[x-1][s]=tmp; return tmp; } void slv(){ n=read(),m=read(); for(int i=0;i<m;i++)x[i]=read(),y[i]=read(),w[i]=read()-1; for(int i=0;i<m;i++)for(int j=0;j<m;j++)if(x[i]==x[j]||y[i]==y[j]||i==j)d[i]|=1ll<<j; jc[0]=1; for(int i=1;i<=n;i++)jc[i]=(ll)jc[i-1]*i%Mod;; for(int i=0;i<=m;i++)add(ans,(ll)jc[n-i]*dfs((1ll<<m)-1,i)%Mod); printf("%d",ans); } bool BBB; signed main(){ // freopen("1.in","r",stdin);freopen("1.out","w",stdout); slv(); // cerr<<clock()*1.0/CLOCKS_PER_SEC<<"s\n"; cerr<<((&AAA)-(&BBB))/1024.0/1024<<"MB\n"; return 0; }