题目链接
LL n, g, b, r, t;
LL dp[MAXN];
int main()
{
int T;
RI(T);
FE(kase, 1, T)
{
cin >> n >> r >> g >> b >> t;
LL ans = n * r * t;
CLR(dp, -1); dp[0] = 0;
REP(all, n)
{
FED(i, n, 0)
{
if (~dp[i])
{
LL nxt = dp[i] + (i * b + t) * (all - i) * g;
if (dp[i + 1] < nxt)
dp[i + 1] = nxt;
nxt = dp[i] + (i * b + t) * (all - i) * g;
if (dp[i] < nxt)
dp[i] = nxt;
}
}
FE(i, 0, n)
{
if (~dp[i])
{
LL nxt = dp[i] + (n - all - 1) * (t + i * b) * (r + (all + 1 - i) * g);
if (ans < nxt)
ans = nxt;
}
}
}
printf("Case #%d: %I64d
", kase, ans);
}
return 0;
}