#include #include #include using namespace std; struct S{ char mp[20][21]; int step,ans,x[50],y[50],val; int num[20][20]; bool operator<(const S &p) const { return val=0 && x=0 && y=0 && x=0 && y=0;i--) { for(j=0;j=0;k--) { if(d[k][j]>'0') { d[i][j]=d[k][j]; d[k][j]='0'; break; } } } } } int t=m-1; while(t--) { for(j=0;j'0') break; if(i==n) { for(i=0;i'0' && !vis[i][j]) { vis[i][j]=1; cnt=1; dfs(i,j,temp[i][j]); if(cnt>1) { node.num[i][j]=cnt; node.val+=cnt*(cnt-1); } } } } int main() { int i,j,p,q,tot; while(~scanf("%d%d",&n,&m)) { for(i=0;ique; eval(t); que.push(t); tot=0; while(!que.empty()) { t=que.top(); if(t.ans>ans.ans) ans=t; tot++; if(tot>24) break; que.pop(); for(i=0;i