为啥子用一维不行捏
查看原帖
为啥子用一维不行捏
657442
wusihao1931楼主2022/11/14 09:21
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int N = 1010;

int n, s, e;
int f[N];

int main()
{
    int v;
    cin >> n >> s >> e;
    f[s] = 1;
    for (int i = 1; i <= n; i ++ )
    {
        cin >> v;
        for (int j = e; j >= 0; j -- )
        {
            if (j - v >= 0) f[j] |= f[j - v];
            if (j + v <= e) f[j] |= f[j + v];
        }
    }
    
    for (int j = e; j >= 0; j -- )
        if (f[j])
        {
            cout << j << endl;
            return 0;
        }
    
    cout << -1 << endl;
    return 0;
}
2022/11/14 09:21
加载中...