Advertisement
Guest User

Untitled

a guest
Feb 7th, 2017
4,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4. #define mod 1000000007
  5. string s;
  6. int arr[26],dp[1005],dp2[1005];
  7. int main()
  8. {
  9.     int n,l=0;
  10.     cin >> n >> s;
  11.     for (int i=0;i<26;i++)
  12.     cin >> arr[i];
  13.     dp[0]=1;
  14.     dp2[0]=0;
  15.     for (int i=1;i<=n;i++)
  16.     {
  17.         int f=0;
  18.         dp2[i]=n;
  19.         for (int x=i-1;x>=0;x--)
  20.         {
  21.             f=max(f,i-arr[s[x]-'a']);
  22.             if (f>x)
  23.             continue;
  24.             dp[i]=(dp[i]+dp[x])%mod;
  25.             dp2[i]=min(dp2[i],1+dp2[x]);
  26.             l=max(l,i-x);
  27.         }
  28.     }
  29.     cout << dp[n] << endl << l << endl << dp2[n] << endl;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement