Make Palindrome
Time Limit: 3000MS Memory Limit:0KB 64bit IO Format:%lld &%llu
SubmitStatusPracticeUVA 10453
1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 6 Charstr[1005];7 intdp[1005][1005],react[1005][1005];8 9 intDfsintXinty)Ten { One if(x>y) A return 0; - if(x==y) -printf"%c", str[x]); the Else if(react[x][y]==0) - { -printf"%c", str[x]); -DFS (x+1, Y1); +printf"%c", Str[y]); - } + Else if(react[x][y]==1) A { atprintf"%c", Str[y]); -DFS (x,y-1); -printf"%c", Str[y]); - } - Else if(react[x][y]==2) - { inprintf"%c", str[x]); -DFS (x+1, y); toprintf"%c", str[x]); + } - return 0; the } * $ intMain ()Panax Notoginseng { - intN; the inti,j,k; + while(SCANF ("%s", str)! =EOF) A { theMemset (DP,0,sizeof(DP)); +memset (React,0,sizeof(react)); - $n=strlen (str); $ for(i=n-1; i>=0; i--) - { - for(j=i+1; j<n;j++) the { - if(str[i]==Str[j])Wuyi { thedp[i][j]=dp[i+1][j-1]; - } Wu Else - { About if(dp[i+1][j]>dp[i][j-1]) $ { -dp[i][j]=dp[i][j-1]+1; -react[i][j]=1; - } A Else + { thedp[i][j]=dp[i+1][j]+1; -react[i][j]=2; $ } the } the } the } the -printf"%d", dp[0][n-1]); inDfs0, N-1); theprintf"\ n"); the } About return 0; the}View Code
UVA 104,537 make Palindrome