有n头狼排成一排,每只狼两个属性,攻击力和加成值,狼的实际攻击力等于自身攻击力加相邻狼的加成值,被杀死之后的狼对相邻的狼的攻击力的加成会被取消,同时,原先与 被杀死的狼相邻的两头狼会变成相邻的狼。问杀死所有狼受到的伤害值最小是。
Input
多组输入,第一行一个T
每组输入一个n(n <= 200)
输入n个数,代表每只狼的攻击力(0<=a[i] <=1e5)
输入n个数,代表每只狼的加成值(0<=b[i]<=5e4)
Output
每组样例输出一个Case,然后输出答案。
Sample Input
2
3
3 5 7
8 2 0
10
1 3 5 7 9 2 4 6 8 10
9 4 1 2 1 2 1 4 5 1
Sample Output
Case #1: 17
Case #2: 74
Hint
In the first sample, Matt defeats the dire wolves from left to right. He takes 5 + 5 + 7 = 17 points of damage which is the least damage he has to take.、
区间DP模板题,先记得将dp[i][j]的后半部,即j>i的部分初始化为最大值,因为是在用后半部分来更新前段
动态转移方程,dp[j][k]=min(dp[j][k],dp[j][x-1]+a[x]+dp[x+1][k]+b[j-1]+b[k+1]);
,每个点要多加当前的攻击值和b数组左右两边的相邻加成
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
#include