注意一下dp的边界条件就行了。。。
#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 1505
#define maxm 100005
#define eps 1e-10
#define mod 3
#define INF 1e9
#define lowbit(x) (x&(-x))
#define ls o<<1
#define rs o<<1 | 1
#define lson o<<1, L, mid
#define rson o<<1 | 1, mid+1, R
typedef long long LL;
//typedef int LL;
using namespace std;
LL dp[maxn][maxn];
LL n, x, y, z, t;
void init(void)
{
memset(dp, 0, sizeof dp);
}
void work(int cas)
{
LL ans = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= i; j++)
dp[i][j] = max(dp[i-1][j-1] + (i - j) * y * (t + (j - 1) * z), dp[i-1][j] + (i - j - 1) * y * ( t + j * z));
dp[i][0] = dp[i-1][0] + (i - 1) * y * t;
}
for(int i = 0; i <= n; i++)
for(int j = 0; j <= i; j++)
ans = max(ans, dp[i][j] + (n - i) * x * (t + j * z) + (n - i) * (t + j * z) * (i - j) * y);
printf("Case #%d: %I64d\n", cas, ans);
}
int main(void)
{
int _, __;
while(scanf("%d", &_)!=EOF) {
__ = 0;
while(_--) {
scanf("%I64d%I64d%I64d%I64d%I64d", &n, &x, &y, &z, &t);
init();
work(++__);
}
}
return 0;
}