Download spoj_cpp_clean/AIBOHP/AIBOHP-4.cpp from slayone/uva_spoj_raw: direct link, hf CLI and curl.
- Browser
- Download file 2.89 kB
-
https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/spoj_cpp_clean/AIBOHP/AIBOHP-4.cpp
- Command line
-
hf download hf://datasets/slayone/uva_spoj_raw/spoj_cpp_clean/AIBOHP/AIBOHP-4.cpp
-
curl -L -o AIBOHP-4.cpp https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/spoj_cpp_clean/AIBOHP/AIBOHP-4.cpp
2.89 kB
| //Data Structure includes | |
| using namespace std; | |
| typedef long long LL; | |
| typedef pair<int,int> PII; | |
| typedef pair<LL,LL> PLL; | |
| typedef pair<int,PII> TRI; | |
| typedef vector<int> VI; | |
| typedef vector<LL> VL; | |
| typedef vector<PII> VII; | |
| typedef vector<PLL> VLL; | |
| typedef vector<TRI> VT; | |
| typedef vector<VI> VVI; | |
| typedef vector<VL> VVL; | |
| typedef vector<VII> VVII; | |
| typedef vector<VLL> VVLL; | |
| typedef vector<VT> VVT; | |
| void chekarre(int * arr,int n) | |
| { | |
| cout<<"["; | |
| for(int i=0;i<n;i++) | |
| cout<<arr[i]<<" "; | |
| cout<<"]"<<endl; | |
| } | |
| inline int haint() | |
| { | |
| int h; | |
| register char c=0; | |
| while (c<33) c=getchar();//getchar_unlocked(); | |
| h=0; | |
| while (c>33) | |
| { | |
| h=h*10+c-'0'; | |
| c=getchar();//getchar_unlocked(); | |
| } | |
| return h; | |
| } | |
| int n, m ; | |
| //string s, s1, s2; | |
| char s1[6200], s2[6200]; | |
| int dp[2][6200];//[6200]; | |
| int main() | |
| { | |
| //freopen("input.txt","r",stdin); | |
| //freopen("output.txt","w",stdout); | |
| int T; | |
| s(T); | |
| while(T--) | |
| { | |
| ss(s1); | |
| n=strlen(s1); | |
| memset(dp,0,sizeof(dp)); | |
| FOR(i,0,n) | |
| s2[i]=s1[n-i-1]; | |
| if(s1[0]==s2[0]) | |
| dp[0][0]=1; | |
| FOR(i,1,n) | |
| { | |
| if(s1[0]==s2[i]) | |
| dp[0][i]=1; | |
| else | |
| dp[0][i]=dp[0][i-1]; | |
| } | |
| FOR(i,1,n) | |
| { | |
| if(s1[i]==s2[0]) | |
| dp[i%2][0]=1; | |
| FOR(j,1,n) | |
| { | |
| if(s1[i]==s2[j]) | |
| { | |
| dp[i%2][j]=1+dp[(i-1)%2][(j-1)]; | |
| } | |
| else | |
| { | |
| dp[i%2][j]=maX(dp[(i-1)%2][j], maX(dp[i%2][(j-1)], dp[(i-1)%2][(j-1)])); | |
| } | |
| } | |
| } | |
| p(n-maX(dp[0][n-1], dp[1][n-1]));printf("\n");//<<endl; | |
| } | |
| return 0; | |
| } | |