Codeforces 150D题目解答

2017-03-29

Codeforces 150D题目解答：删长度为x的回文串 会有得分ax 删完拼在一起 问最大得分。

Codeforces 150D题目解答：删长度为x的回文串 会有得分ax 删完拼在一起 问最大得分。

```#include
#include
#include
#include
using namespace std;

inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
}
char c=nc(),b=1;
for (;!(c>=&#39;0&#39; && c<=&#39;9&#39;);c=nc()) if (c==&#39;-&#39;) b=-1;
for (x=0;c>=&#39;0&#39; && c<=&#39;9&#39;;x=x*10+c-&#39;0&#39;,c=nc()); x*=b;
}
char c=nc(); int len=0;
for (;!(c>=&#39;a&#39; && c<=&#39;z&#39;);c=nc());
for (;c>=&#39;a&#39; && c<=&#39;z&#39;;s[++len]=c,c=nc()); s[++len]=0; return len-1;
}

const int N=155;

int n,a[N]; char s[N];
int f[N][N][N],g[N][N];
int ans[N];

int main(){
freopen("t.in","r",stdin);
freopen("t.out","w",stdout);
memset(f,-0x3f,sizeof(f));
memset(g,-0x3f,sizeof(g));
for (int i=1;i<=n+1;i++) g[i][i-1]=0;
for (int i=n;i;i--)
for (int j=i;j<=n;j++)
for (int k=1;k<=j-i+1;k++){
if (s[i]==s[j]){
if (k==1)
f[i][j][k]=max(g[i][j-1],g[i+1][j]);
else if (k==2)
f[i][j][k]=max(f[i][j][k],g[i+1][j-1]);
else
f[i][j][k]=max(f[i][j][k],f[i+1][j-1][k-2]);
}
for (int x=i;x

```