help me visualize how this program uses dp to solve a problem. The program: #include #include #include #include using namespace std; int minDeletions(string s) { int n = s.size(); if (n == 0) return 0; // dp[i][j] = minimum deletions to clear substring s[i..j] vector> dp(n, vector(n, 0)); // Base case: one letter is always one operation for (int i = 0; i < n; i++) { dp[i][i] = 1; } // Build up from shorter substrings to longer for (int len = 2; len <= n; len++) { for (int i = 0; i + len - 1 < n; i++) { int j = i + len - 1; // Option 1: remove s[i] alone, then the rest dp[i][j] = 1 + dp[i+1][j]; // Option 2: try to merge s[i] with a matching character later for (int k = i+1; k <= j; k++) { if (s[k] == s[i]) { // cost to delete the middle part + dp for block starting at k int cost = dp[i+1][k-1] + dp[k][j]; dp[i][j] = min(dp[i][j], cost); } } } } return dp[0][n-1]; } int main() { string s; cout << "Enter the string: "; cin >> s; cout << "Minimum operations to delete string: " << minDeletions(s) << endl; return 0; } the problem: Minimum operations required to make a string empty. In one ops can only delete one block at a time. This block will only contain the same character. It can be of length 1

视频信息