标签:
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 372 Accepted Submission(s): 161
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<string> #include<algorithm> #include<cstdlib> using namespace std; long long mp[20][20],A[20],dp[(1<<17)+5]; int n,m; void AA() { A[0]=1; for(int i=1;i<=18;i++) A[i]=i*A[i-1]; } int main() { int tt,ca=1; scanf("%d",&tt); AA(); while(tt--) { memset(mp,0,sizeof(mp)); memset(dp,0,sizeof(dp)); scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { int a,b; scanf("%d%d",&a,&b); a--,b--; mp[a][b]=1; } dp[0]=1; for(int i=0;i<n;i++) { for(int j=(1<<n)-1;j>=0;j--) { if(dp[j]==0) continue; for(int k=0;k<n;k++) { if((j&(1<<k))) continue; if(mp[i][k]) continue; dp[j|(1<<k)]+=dp[j]; } } } printf("Case %d: %I64d\n",ca++,A[n]-dp[(1<<n)-1]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/water-full/p/4488506.html