ICPC過去問
Problem B: 列車の編成パートII
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1142&lang=jp
解法:前列+後列、後列+前列、逆前列+後列...etc で結果をソートして個数を数え上げる
includeやテンプレは省略
テンプレ:http://henteko07.hatenablog.com/entry/2012/06/18/001535
string re(string s) { string ss = ""; for(int i=SZ(s)-1;i >= 0;i--) { ss += s[i]; } return ss; } int main() { int m = cin_i(); REP(i,m) { string s =cin_s(); VS date; REP(j,SZ(s)-1) { string fs = ""; REP(k,j+1) fs += s[k]; string bs = ""; FOR(k,j+1,SZ(s)) bs += s[k]; string rfs = re(fs); string rbs = re(bs); date.PB(fs + bs); date.PB(rfs + bs); date.PB(fs + rbs); date.PB(rfs + rbs); date.PB(bs + fs); date.PB(rbs + fs); date.PB(bs + rfs); date.PB(rbs + rfs); } SORT(date); int count = 1; string ss = date[0]; REP(j,SZ(date)-1) { if(ss != date[j+1]) { count++; ss = date[j+1]; } } cout << count << endl; } }