直接建树伪哈希,哈希大法好,哈希出奇迹
然而本非好久没刷题了,WA了好多发,orz
#include<cstdio> #include<cstring> #include<algorithm> #include<map> using namespace std; #define ul unsigned long long const ul mod=1000000009; const ul modx=100000007; const int maxn=2008; struct fuck{ int u,left,right; }edge[maxn]; int tol; void init() { tol=0; } ul mody; void fuckbitch(int x) { edge[tol].u=x; edge[tol].left=-1; edge[tol].right=-1; tol++; } bool dfs(int u,int x) { if(u==-1) { fuckbitch(x); return true; } if(edge[u].u>x) { if(dfs(edge[u].left,x)) edge[u].left=tol-1; } else { if(dfs(edge[u].right,x)) edge[u].right=tol-1; } return false; } map<ul,int> mp; void fuckdfs(int u,ul md) { mody=mody*modx+md; if(edge[u].left!=-1) fuckdfs(edge[u].left,(md<<1)); if(edge[u].right!=-1) fuckdfs(edge[u].right,(md<<1|1)); } int main() { int t,i,j,x; int n,m; scanf("%d%d",&n,&m); int sum=n; mp.clear(); for(i=1;i<=n;i++) { mody=0; init(); for(j=1;j<=m;j++) { scanf("%d",&x); if(j==1) fuckbitch(x); else dfs(0,x); } fuckdfs(0,1); ul ans=mody; if(mp[ans]==0) mp[ans]++; else sum--; } printf("%d ",sum); return 0; }