You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
446 B
30 lines
446 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
/*
|
|
测试用例:
|
|
5
|
|
12321
|
|
|
|
*/
|
|
int cnt = 1;
|
|
|
|
// 递归写法
|
|
void dfs(string s) {
|
|
int p;
|
|
for (p = s.size() - 1; p >= 1; p--)
|
|
if (s[0] != s[p]) break;
|
|
|
|
string t;
|
|
for (int i = 1; i <= p; i++) t += s[i];
|
|
if (t.size()) cnt++, dfs(t);
|
|
}
|
|
|
|
int main() {
|
|
int n;
|
|
string s;
|
|
cin >> n >> s;
|
|
dfs(s);
|
|
cout << cnt << endl;
|
|
return 0;
|
|
} |