(dp) acwing 1024. 装箱问题

1024. 装箱问题

题目链接
在这里插入图片描述

#include<iostream>
#include<algorithm>

using namespace std;
int main() {
    
    
	int v, n;
	cin >> v >> n;
	int a;
	int dp[20010] = {
    
     0 };
	for (int i = 1; i <= n; i++) {
    
    
		cin >> a;
		for (int j = v; j >= a; j--) {
    
    
			dp[j] = max(dp[j], dp[j - a] + a);
		}
	}
	cout << v-dp[v];
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_46028214/article/details/115326855