Colorful Subsequence
题目描述
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
提示
Since all characters in S itself are different, all its subsequences satisfy the condition.
ps:这个题有点小坑。字串所有字符都要不同。所以最多26个字符。不同位置算不同。所以把26个字符每个字符的位置(数量)统计出来,+1,连乘。再-1;、
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int a[26];
int main(int argc, char *argv[])
{
int n;
cin>>n;
string s;
cin>>s;
for(int i=0;i<s.length();i++){
a[s[i]-'a']++;
}
ll ans=1;
for(int i=0;i<26;i++){
ans=ans*ll(a[i]+1)%mod;
}
cout<<ans-1<<endl;
return 0;
}