思路
dp
过程
代码
#include <iostream>
#include <unordered_map>
using namespace std;
const int N = 1e5 + 10;
typedef long long LL;
int n;
string s;
LL h[26], ch[26];
int main()
{
cin >> n >> s;
LL ans = 0;
for(int i = 0;i < n;i ++)
{
char x = s[i] - 'a';
ans += h[x];
h[x] = h[x] + i - ch[x];
ch[x] ++;
}
cout << ans << endl;
return 0;
}