有没有佬能给我解释一下呀(看我的注释)
查看原帖
有没有佬能给我解释一下呀(看我的注释)
1461843
faithz楼主2025/1/7 16:37
#include <bits/stdc++.h>

using namespace std;

const int N = 2e6 + 5;
int f[N];
int v[N];
int main()
{
    int V,n;
    cin >> V >> n;
    for(int i = 1;i <= n;i++)cin >> v[i];

    for(int i = 1;i <= n;i++)
    {
        //如果我使j = 0,j <= V,j++,会导致什么结果呀?
        for(int j = V;j >= v[i];j--)
            f[j] = max(f[j],f[j - v[i]] + v[i]);
    }
    cout << V - f[V];
    return 0;
}
2025/1/7 16:37
加载中...