题目描述
You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 109+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings.
Here, a subsequence of a string is a concatenation of one or more characters from the string without changing the order.
Constraints
·1≤N≤100000
·S consists of lowercase English letters.
·|S|=N
输入
Input is given from Standard Input in the following format:
N
S
输出
Print the number of the subsequences such that all characters are different, modulo 109+7.
样例输入
4
abcd
样例输出
15
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
map<char,int>mp;
const int maxn = 100000+10;
const long long mod = 1e9+7;
char a[maxn];
int main()
{
int n;
scanf("%d%s",&n,&a);
for(int i=0;i<n;i++)
{
mp[a[i]]++;
}
long long ans=1;
for(char i='a';i<='z';i++)
{
ans*=(mp[i]+1);
ans%=mod;
}
printf("%lld\n",ans-1);
}
提示
Since all characters in S itself are different, all its subsequences satisfy the condition.