标签:
Time Limit: 4000MS | Memory Limit: 65536K | |
Total Submissions: 3709 | Accepted: 1422 |
Description
Input
Output
Sample Input
3 4 2 1 4 2 1 3 2 2 4
Sample Output
4
Source
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #include<string> using namespace std; int n,m,mp[21][21]; int dp[(1<<20)+2]; int main() { scanf("%d%d",&n,&m); for(int i=0;i<n;i++) { int x,y; scanf("%d",&x); while(x--) { scanf("%d",&y); y--; mp[i+1][y]=1; } } if(n>m) { printf("0\n"); return 0; } dp[0]=1; for(int i=0;i<n;i++) { for(int j=(1<<m)-1;j>=0;j--) { if(dp[j]==0) continue; for(int k=0;k<m;k++) { if((j&(1<<k))!=0) continue; if(mp[i+1][k]==0) continue; dp[j|(1<<k)]+=dp[j]; } dp[j]=0; } } int ans=0; for(int i=0;i<(1<<m);i++) ans+=dp[i]; printf("%d\n",ans); return 0; }
标签:
原文地址:http://www.cnblogs.com/water-full/p/4488723.html