返回小组 开始 2026-08-27 13:30:00

8.27下午动态规划专题(背包、完全、线性)

结束 2026-08-27 16:00:00
Contest is over.
当前 2026-09-03 18:40:18

qwertyuiop

include <bits/stdc++.h>

using namespace std; const int N = 20005, M = 1e9; int dp[N], a[N], b[N];

int main() {

int n, m;
cin >> n >> m;
for (int x = 1; x <= m; x++)
	cin >> a[x];
for (int x = 0; x < n; x++)
	cin >> b[x];
for (int x = 0; x < N; x++)
	dp[x] = -M;
dp[0] = 0;
for (int x = 0; x < n * 2; x++)
	for (int y = 1; y <= m; y++)
		if (x >= a[y])
			dp[x] = max(dp[x], dp[x - a[y]] + b[x - a[y]]);
int ans = -M;
for (int x = n; x <= n * 2; x++)
	ans = max(ans, dp[x]);
cout << ans;
return 0;

}


McQueen  •  7天前

比赛已结束。