Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <algorithm>
- using namespace std;
- int main() {
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- const int INF = 1e9;
- string strA, strB;
- fin >> strA;
- int nA = strA.size();
- int nB = 3;
- strA += 'A';
- strB = "sisA";
- vector<vector<int>> dp(nA + 2, vector<int>(nB + 2, INF));
- dp[0][0] = 0;
- for (int i = 0; i <= nA; i++)
- for (int j = 0; j <= nB; j++) {
- if (strA[i] == strB[j])
- dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);
- for (int k = i + 1; k <= nA; k++)
- dp[k][j] = min(dp[k][j], dp[i][j] + 1);
- }
- fout << (dp[nA][3] == INF ? -1 : dp[nA][3]) << endl;
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment