实话实说一开始把这题稍微想的麻烦了一些,因为太像以前做过的题了,hhh(菜是原罪)
解题思路:
- 很简单,想三个位置不一样,想有多少种,那么直接Cn3就OK了,
- 然后注意取模
代码:
#include <iostream>
#include <cstdio>
using namespace std;
const int Mod = 1e9 + 7;
long long ans[30];
int main(){
int n;
scanf("%d",&n);
string st;
cin>>st;
for (int i = 0; i < n; i++){
ans[st[i] - 'a'] ++;
}
long long res = 0;
for (int i = 0 ; i < 26; i ++){
if (ans[i] >= 3){
res = (res + ans[i] * (ans[i] - 1) * (ans[i] - 2) / 6 % Mod) % Mod ;
}
}
printf("%lld\n",res);
return 0;
}