feat: new dp problem formatted

This commit is contained in:
2025-12-19 07:49:39 -03:00
parent 409b0a324c
commit 1223e55c49
88 changed files with 6652 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n; cin >> n;
string s; cin >> s;
/*
dp[i][j] says if the substring from i to j is a palindrome
*/
vector<vector<int>> dp(n, vector<int>(n, 0));
for (int i = n - 1; i >= 0; i--)
{
dp[i][i] = 1;
for (int j = i + 1; j < n; j++)
{
if (s[i] == s[j])
{
dp[i][j] = dp[i + 1][j - 1] + 2;
}
else
{
dp[i][j] = max(dp[i + 1][j], dp[i][j - 1]);
}
}
}
cout << dp[0][n - 1] << endl;
return 0;
}