# Maximize the cut segments

https://practice.geeksforgeeks.org/problems/cutted-segments/0
class Solution { int dp[10005]; int solve(int x, int a, int b, int c) { if (dp[x] != -1) return dp[x]; if (x < min({a, b, c})) return dp[x] = INT_MIN; int n1 = (x >= a) ? solve(x - a, a, b, c) + 1 : INT_MIN; int n2 = (x >= b) ? solve(x - b, a, b, c) + 1 : INT_MIN; int n3 = (x >= c) ?

# Longest common subsequence

https://practice.geeksforgeeks.org/problems/longest-common-subsequence/0
Iterative
class Solution { int dp[1005][1005]; public: int lcs(int x, int y, string s1, string s2) { for (int i = 0; i <= x; i++) { for (int j = 0; j <= y; j++) { if (i == 0 || j == 0) { dp[i][j] = 0; } else if (s1[i - 1] == s2[j - 1]) { dp[i][j] = dp[i - 1][j - 1] + 1; } else { dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } } } return dp[x][y]; } }; Recursive