1 solutions
-
0
C++ :
#include <bits/stdc++.h> #define N 100005 using namespace std; int a[N]; long long dp[N]; int main(){ int n; string s; cin >> n >> s; for (int i = 1;i<=n;i++) cin >> a[i]; s = " " + s; int start = 0; for (int i = 1;i<=n;i++){ dp[i] = a[1] + dp[i-1]; for (int len = 2;len<=26;len++){ int pos = i - len + 1; if (pos <= start) break; if (s[pos] == s[i]) { start = pos; break; } dp[i] = max(dp[pos-1] + a[len] , dp[i]); } } cout << dp[n]; return 0; }
- 1
Information
- ID
- 127
- Time
- 1000ms
- Memory
- 512MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By