原题
加法游戏
因为最后两个也要被削掉,所以当成有n+2个数,分别为0位置和n+1位置,他们的主攻击力和次攻击力都为0即可
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 210
using namespace std;
int t,n,a[N],b[N],f[N][N];
int main()
{
scanf("%d",&t);
for (int q=1;q<=t;q++)
{
printf("Case #%d: ",q);
memset(f,127,sizeof(f));
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d",&a[i]);
for (int i=1;i<=n;i++)
scanf("%d",&b[i]);
for (int i=0;i<=n+1;i++)
f[i][i]=a[i],f[i][i+1]=0;
for (int d=1;d<=n+1;d++)
for (int i=0,j;i+d<=n+1;i++)
{
j=i+d;
for (int k=i+1;k<j;k++)
f[i][j]=min(f[i][j],f[i][k]+f[k][j]+b[i]+b[j]+a[k]);
}
printf("%d
",f[0][n+1]);
}
return 0;
}