int main() { int n; while(cin>>n && n) { map<string,bool> sw; string s,abr; for(int i=0;i<n;i++){ cin>>s; sw[s]=1; //mark insignificant words } getline(cin,s); while(getline(cin,s) && s!="LAST CASE") { w.clear(); stringstream ss; ss<<s; ss>>a; abr=a; for(int i=0;i<a.size();i++) a[i]=tolower(a[i]); while(ss>>s) if(sw.find(s)==sw.end()) w.PB(s); memset(dp,-1,sizeof(dp)); int res=solve(0,0,0); if(res==0) cout<<abr<<" is not a valid abbreviation"<<endl; else cout<<abr<<" can be formed in "<<res<<" ways"<<endl; } } }
string ColorfulStrings::getKth (int n, int k) { if(n > 8) return ""; k--; cl(used, 0); strs.clear(); generate(0, n); return ""; }
int main(int argc, char **argv){ ios_base::sync_with_stdio(0); cin.tie(0); int t; cin>>t; string s; int n; bool first=true; while(t--){ if(!first) cout<<'\n'; else first=false; cin>>s; n=s.size(); v.clear(); sum.clear(); v.resize(n); sum.resize(n,vi(n,0)); v[0]=s; for(int i=1;i<n;++i)cin>>v[i]; for(int i=0;i<n;++i) for(int j=0;j<n;++j){ sum[i][j]=(v[i][j]-'0'); if(i>0) sum[i][j]+=sum[i-1][j]; if(j>0) sum[i][j]+=sum[i][j-1]; if(i>0 && j>0) sum[i][j]-=sum[i-1][j-1]; } int largest=0,sumhere; /*for(int i=0;i<n;++i) for(int j=0;j<n;++j)cout<<sum[i][j]<<(j==n-1?'\n':' ');*/ for(int i=0;i<n;++i)for(int j=0;j<n;++j) for(int p=i;p<n;++p)for(int q=j;q<n;++q){ //cout<<"("<<i<<","<<j<<") . "<<"("<<p<<","<<q<<")"<<endl; sumhere=sum[p][q]; if(i>0) sumhere-=sum[i-1][q]; if(j>0) sumhere-=sum[p][j-1]; if(i>0 && j>0) sumhere+=sum[i-1][j-1]; if(v[i][j]=='1' && sumhere==(p-i+1)*(q-j+1)) largest=max(largest,sumhere); } cout<<largest<<'\n'; } return 0; }
void add (int si, int fi, int sj, int fj) { string t; temp.clear(); for (int i = si; i < fi; i++){ for (int j = sj; j < fj; j++) { t.push_back(b[i][j]); } temp.push_back(t); } if (SET.find(temp) == SET.end()) SET.insert(temp); else { fail = 1; return; } for (int i = ) }