1 solutions
-
0
/* * __----~~~~~~~~~~~------___ * . . ~~//====...... __--~ ~~ * -. \_|// |||\\ ~~~~~~::::... /~ * ___-==_ _-~o~ \/ ||| \\ _/~~- * __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ * _-~~ .=~ | \\-_ '-~7 /- / || \ / * .~ .~ | \\ -_ / /- / || \ / * / ____ / | \\ ~-_/ /|- _/ .|| \ / * |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ * ' ~-| /| |-~\~~ __--~~ * |-~~-_/ | | ~\_ _-~ /\ * / \ \__ \/~ \__ * _--~ _/ | .-~~____--~-/ ~~==. * ((->/~ '.|||' -_| ~~-/ , . _|| * -_ ~\ ~~---l__i__i__i--~~_/ * _-~-__ ~) \--______________--~~ * //.-~~~-~_--~- |-------~~~~~~~~ * //.-~~~--\ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * 神兽保佑 永无BUG */ /* * @Description: I want to be the weakest vegetable in the world! * @Author: I.Z. */ #include<bits/stdc++.h> using namespace std; #define MOD 1000000007 #define speMOD 2933256077ll #define int long long #define pii pair<int,int> #define all(v) v.begin(),v.end() #define pb push_back #define REP(i,b,e) for(int i=(b);i<(int)(e);++i) #define over(x) {cout<<(x)<<endl;return;} #define lowbit(x) ((x)&(-(x))) #define cntbit(x) __builtin_popcount(x) #define rf(v) shuffle(all(v),sd); #define deal(v) sort(all(v));v.erase(unique(v.begin(),v.end()),v.end()) #define lbound(v,x) lower_bound(all(v),x)-v.begin() mt19937 sd(random_device{}()); int qpow(int a,int b,int m=MOD,int res=1){ a%=m; while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1; return res; } string YN(bool x,string Y="Yes",string N="No") { if(x){ return Y; } else { return N; } } int exgcd(int x,int y,int &a,int &b){ if(y==0){ a=1;b=0; return x; } int d=exgcd(y,x%y,a,b); int z=b; b=a-b*(x/y); a=z; return d; } int _x_,_y_; inline int inverse(int x,int y=MOD){ exgcd(x,y,_x_,_y_); return (_x_+y)%y; } int fac[2000005],inv[2000005]; void init(int n){ fac[0]=inv[0]=1; REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD; inv[n]=qpow(fac[n],MOD-2); for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD; } int binom(int x,int y){ return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD; } int N,n,m; signed p1[10],p2[10],tp[10]; int a[10][10]; int res,sum; int dp[10][2100000],pd[10][2100000],S[10]; void dfs(int x){ if(x==0){ p1[0]=p2[0]=tp[0]=0; dfs(x+1); return; } REP(j,0,x-1){ int i=x-1; bool f=0; if(p1[i]==p1[j]&&p2[i]==p2[j])f=1; else if(p1[i]+tp[i]==p1[j]&&p2[i]+1-tp[i]==p2[j])f=1; else if(p1[i]==p1[j]+tp[j]&&p2[i]==p2[j]+1-tp[j])f=1; else if(p1[i]+tp[i]==p1[j]+tp[j]&&p2[i]+1-tp[i]==p2[j]+1-tp[j])f=1; a[j][i]=f; } { signed X,Y,m1=0,m2=0; REP(i,0,x)m1=max(m1,p1[i]+tp[i]),m2=min(m2,p1[i]); X=m1-m2+1; m1=m2=0; REP(i,0,x)m1=max(m1,p2[i]+1-tp[i]),m2=min(m2,p2[i]); Y=m1-m2+1; res=0; if(X<=n&&Y<=m)(res+=(n-X+1)*(m-Y+1))%=MOD; if(X<=m&&Y<=n)(res+=(m-X+1)*(n-Y+1))%=MOD; int c=0,r=0; REP(i,0,x){ REP(j,0,i){ r+=(a[j][i]<<c);++c; } } // if(r==7&&x==N)REP(i,0,N)cout<<p1[i]<<' '<<p2[i]<<' '<<tp[i]<<" "; // if(r==7&&x==N)cout<<endl<<' '<<X<<' '<<Y<<' '<<res<<endl; (pd[x][S[x]^r]+=res)%=MOD; } if(x==N)return; REP(t,0,2){ REP(i,-x,x+1){ REP(j,-x,x+1){ bool f=0; REP(l,0,x){ if(i==p1[l]&&j==p2[l]){f=1;break;} if(i+t==p1[l]&&j+1-t==p2[l]){f=1;break;} if(i==p1[l]+tp[l]&&j==p2[l]+1-tp[l]){f=1;break;} if(i+t==p1[l]+tp[l]&&j+1-t==p2[l]+1-tp[l]){f=1;break;} } if(f){ p1[x]=i;p2[x]=j;tp[x]=t; dfs(x+1); } } } } } int k; int vis[10]; int b[10][10]; vector<int>g[10]; int st[100],fr,ls; int v[10]; void Main() { cin>>n>>m>>k; REP(i,1,k+1)S[i]=(1<<(i*(i-1)/2))-1; // cout<<clock()<<endl; N=k;dfs(0); // cout<<clock()<<endl; REP(i,1,k+1){ int s=i*(i-1)/2; REP(j,0,s){ REP(l,0,(1<<s)){ if((l>>j)&1)(pd[i][l]+=pd[i][l^(1<<j)])%=MOD; } } REP(j,0,(1<<s))dp[i][j]=pd[i][((1<<s)-1)^j]; } // cout<<clock()<<endl; int s=k*(k-1)/2,ans=0;//,t=(2*n*m-n-m)%MOD; REP(i,0,(1<<s)){ REP(j,0,k)vis[j]=0; int cur=0; // REP(j,0,k)g[j].clear(); REP(j,0,k){ REP(l,0,j){ b[l][j]=b[j][l]=(i>>cur)&1; ++cur; // if(b[l][j])g[j].pb(l),g[l].pb(j); } } cur=1; REP(j,0,k)if(!vis[j]){ // if(!g[j].size()){(cur*=t)%=MOD;continue;} N=0; st[0]=j;vis[j]=1;fr=0;ls=0; while(fr<=ls){ int x=st[fr];++fr;v[N++]=x; REP(l,0,k)if(b[l][x]&&!vis[l])st[++ls]=l,vis[l]=1; } int c=0,r=0; REP(l,0,N){ REP(l2,0,l)r+=b[v[l]][v[l2]]<<c,++c; } // sort(all(v)); // for(auto l:v)cout<<l+1<<' '; // cout<<endl; // cout<<r<<endl; (cur*=dp[N][r])%=MOD; } // cout<<cur<<endl; // cout<<endl; if(cntbit(i)%2==0)ans+=cur; else ans+=MOD-cur; } ans%=MOD; REP(i,0,k)(ans*=inverse(i+1))%=MOD; cout<<ans<<endl; // cout<<clock()<<endl; } void TC() { int tc=1; while(tc--){ Main(); cout.flush(); } } signed main() { freopen("domino.in","r",stdin); freopen("domino.out","w",stdout); return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0; } /* 1. CLEAR the arrays (ESPECIALLY multitests) 2. DELETE useless output */
- 1
Information
- ID
- 2923
- Time
- 3000ms
- Memory
- 512MiB
- Difficulty
- 10
- Tags
- (None)
- # Submissions
- 1
- Accepted
- 1
- Uploaded By