SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <bits/stdc++.h> | |
| 2 | ||
| 3 | using namespace std; | |
| 4 | int input(){
| |
| 5 | int res = 0; char c = ' '; | |
| 6 | while (c < '0') c = getchar(); | |
| 7 | while (c >= '0') res = res * 10 + (c - '0'), c = getchar(); | |
| 8 | return res; | |
| 9 | } | |
| 10 | const int N = 1e5 + 1, MOD = 1e9 + 7; | |
| 11 | ||
| 12 | int sum(int f, int s){
| |
| 13 | return (f + s < MOD ? f + s : f + s - MOD); | |
| 14 | } | |
| 15 | int dif(int f, int s){
| |
| 16 | return (f - s < 0 ? f - s + MOD : f - s); | |
| 17 | } | |
| 18 | int f[N], cnt[10], a[N], cur; | |
| 19 | int main(){
| |
| 20 | int n = input(); | |
| 21 | for (int i = 1; i <= n; ++ i){
| |
| 22 | char c; cin >> c; | |
| 23 | a[i] = c - '0'; | |
| 24 | } | |
| 25 | f[0] = 1; | |
| 26 | ||
| 27 | for (int i = 1, j = 1; i <= n; ++ cnt[a[i ++]]){
| |
| 28 | while (cnt[a[i]]){
| |
| 29 | cur = dif(cur, f[j]); | |
| 30 | -- cnt[a[j]], ++ j; | |
| 31 | } | |
| 32 | cur = sum(cur, f[i] = sum(cur, f[j - 1])); | |
| 33 | } | |
| 34 | cout << f[n]; | |
| 35 | } |