记忆化搜索
取数游戏2
https://ac.nowcoder.com/acm/problem/14701
并没有很快的想到转移方程,所以就直接搜索吧。(写起来超短的)
int dfs(int cur, int l) { if (cur == n + 1) return 0; if (memo[cur][l] != 0) return memo[cur][l]; return memo[cur][l] = max(dfs(cur + 1, l) + a[n - cur + l] * b[cur], dfs(cur + 1, l + 1) + a[l] * b[cur]); } void solve() { memset(memo, 0, sizeof memo); cin >> n; rep(i, 1, n) cin >> a[i]; rep(i, 1, n) cin >> b[i]; cout << dfs(1, 1) << endl; } int main() { int T; cin >> T; while (T--) { solve(); } }