AC

名字不要取太长像我这样应该刚刚好  •  20天前


include <bits/stdc++.h>

using namespace std; int a[105], b[20010], d[20010]; const int M = 1e9;

int main() {

int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++)
	cin >> a[i];
for (int i = 0; i < n; i++)
	cin >> b[i];
for (int i = 0; i < n << 1; i++)
	d[i] = -M;
d[0] = 0;
for (int i = 0; i < n << 1; i++)
	for (int j = 0; j < m; j++)
		if (i >= a[j])
			d[i] = max(d[i], d[i - a[j]] + b[i - a[j]]);
int maxn = -M;
for (int i = n; i < n * 2; i++) 
	maxn = max(maxn, d[i]);	
cout << maxn;
return 0;

}


评论:

请先登录,才能进行评论