Ultraviolet A 10617 Again Palindrome (DP)
You can delete a string and delete any number of characters (which can be 0) at any position. Q: There are several ways to delete the original string into a return string. Solution: dp [I] [j] = 1 (I = j). A single character is also the return string s [I]! = S [j, dp [I] [j] = dp [I + 1] [j] + dp [I] [j-1]-dp [I + 1] [j-1], dp [I + 1] [j] and dp [I] [j + 1] public part dp [I + 1] [j-1] should be removed once s [I] = s [j, dp [I] [j] = dp [I + 1] [j] + dp [I] [j-1] + 1, when s [I] = s [j], it is worse than s [I]! = S [j, is the dp [I + 1] [J-1] in any substring can be added at the same time before and after s [I] And s [j], and s [I] s [j] is also a response string
#include
#include
#include #include
#include
using namespace std;typedef long long ll;char s[100];ll dp[100][100];int main() { int T; scanf("%d", &T); while (T--) { scanf("%s", s); int len = strlen(s); for (int i = 0; i < len; i++) { dp[i][i] = 1; } for (int i = len - 2; i >= 0; i--) { for (int j = i + 1; j < len; j++) { if (s[i] == s[j]) { dp[i][j] = dp[i + 1][j] + dp[i][j - 1] + 1; } else { dp[i][j] = dp[i + 1][j] + dp[i][j - 1] - dp[i + 1][j - 1]; } } } printf("%lld\n", dp[0][len - 1]); } return 0;}