提交时间:2022-07-19 11:51:33
运行 ID: 52279
#include<bits/stdc++.h> using namespace std; inline int read(){ int X=0,w=0; char ch=0; while(!isdigit(ch)) {w|=ch=='-';ch=getchar();} while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); return w?-X:X; } inline void write(int x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } int n,m; int k[4001]; int e[4001][41]; int dp[1000001][11]; int main(){ n=read(),m=read(); for(int i=1;i<=m;i++){ k[i]=read(); for(int j=1;j<=k[i];j++) e[i][j]=read(); } memset(dp,0,sizeof(dp)); for(int i=1;i<=m;i++){ for(int a=1;a<=k[i];a++){ for(int b=a+1;b<=k[i];b++){ int x=e[i][a],y=e[i][b]; for(int S=0;S<(1<<n);S++){ if((S^(1<<(x-1)))>S&&(S^(1<<(y-1)))>S){ dp[S^(1<<(x-1))^(1<<(y-1))][i]=max(dp[S^(1<<(x-1))^(1<<(y-1))][i],dp[S][i-1]+1); // cout<<S<<" "; } else dp[S][i]=max(dp[S][i-1],dp[S][i]); } } } } int ans=0; for(int S=0;S<(1<<n);S++) ans=max(ans,dp[S][m]); write(ans); return 0; }