GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GeeksForGeeks/string/FormPalindrome.cpp at master · varunswing/GeeksForGeeks

Expand file tree

/

FormPalindrome.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
39 lines (36 loc) · 776 Bytes
/

FormPalindrome.cpp

Copy path

File metadata and controls

39 lines (36 loc) · 776 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;
int lcs(string s, int x){
string t = s;
reverse(t.begin(), t.end());
int y = t.length();
int dp[x+1][y+1];
for(int i=0;i<=x;i++)
dp[i][0] = 0;
for(int j=0;j<=y;j++)
dp[0][j] = 0;
for(int i=1;i<=x;i++){
for(int j=1;j<=y;j++){
if(s[i-1] == t[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];
}
int minInsertions(string s, int n){
int x = lcs(s, n);
return n-x;
}
int main() {
int t;
cin>>t;
while(t--){
string s;
cin>>s;
int n = s.length();
cout<<minInsertions(s, n)<<endl;
}
return 0;
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.