nnd

陈祉尹  •  22小时前


include <bits/stdc++.h>

using namespace std; int n, m, ans, dp[20030]; struct node { int w, v; } a[1010]; //砖块 bool cmp(node pre, node nxt) { return pre.w + pre.v <= nxt.w + nxt.v; } //排序 int main() {

cin >> n;
for (int i = 1; i <= n; ++ i) cin >> a[i].w >> a[i].v;
sort(a + 1, a + n + 1, cmp);
for (int i = 1; i <= n; ++ i)
	for (int j = a[i].w + a[i].v; j >= a[i].w; -- j)
		dp[j] = max(dp[j], dp[j - a[i].w] + a[i].v), //01背包 
		ans = max(ans, dp[j]); //求最大 
cout << ans;
return 0;

}


评论:

请先登录,才能进行评论