蓝桥集训之松散子序列
-
核心思想:状态机+dp
-
每个点两种状态
-
f[i,0] = max(f[i-1,0] , f[i-1,1])
-
f[i,1] = f[i-1,0] + w;
-
#include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 1000010; int f[N][2]; int n; char str[N]; int main() { cin>>str+1; n = strlen(str+1); for(int i=1;i<=n;i++) { f[i][0] = max(f[i-1][0] , f[i-1][1]); f[i][1] = f[i-1][0] + str[i] - 'a' + 1; } cout<<max(f[n][0] , f[n][1])<<endl; return 0; }