Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define nl "\n"
- #define cnl cout << nl;
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define ull unsigned ll
- #define RV return void
- #define sz(x) int(x.size())
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define fixed(n) fixed << setprecision(n)
- #define cin(v) for(auto&x:v) cin >> i;
- #define cout(v) for(auto&x:v) cout << i << " ";
- void files(){
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- int n ;
- string s;
- vector < vector < ll > > dp;
- bool valid(int st , int end){
- if(end - st + 1 > 10 ) return false;
- int freq[10]{};
- for(int i = st ; i <= end ; i++){
- if(freq[s[i]-'0'] > 0) return false;
- freq[s[i]-'0']++;
- }
- return true;
- }
- ll mod = 1e9+7;
- ll rec(int idx , int cnt){
- if(idx >= n-1 ) {
- if(idx == n -1 and valid(idx -cnt , idx )) return 1;
- else return 0;
- }
- ll & ret = dp[idx][cnt];
- if(~ret)
- return ret ;
- ret =0;
- if(cnt < 10 ){
- ret += rec(idx+1 , cnt+1);
- ret %= mod;
- }
- if(valid(idx-cnt , idx)) {
- ret += rec(idx+1 , 0);
- ret %= mod;
- }
- return ret ;
- }
- void solve(){
- cin >> n >> s;
- dp.assign(n+1 , vector < ll > (20 , -1));
- cout << rec(0,0) << nl;
- }
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- // files();
- int testCase=1;
- // cin >> testCase ;
- for(int i=1 ; i <= testCase ; i++){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement