Man,what can I say??(say了闭关)
查看原帖
Man,what can I say??(say了闭关)
772815
一咕咕一楼主2024/8/16 11:52

这是100分代码:

#include <bits/stdc++.h>
#define USED(VAL) VAL++, VAL--
#define Max (MaxNum - 7)
#define INF 0x3f3f3f3f
#define FastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define max(a, b) (a < b ? b : a)
#define min(a, b) (a < b ? a : b)
#define Endl cout << "\n"
#define endl '\n'

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;
typedef long double LD;

const int MaxNum = 1000 + 7;

/*The function of the code was {the functions and ideas...}*/

/*Functions...*/
LL sum[MaxNum], a[MaxNum], ans, n, c;
inline void DFS(int ind, LL s)
{
    if (s > c)
        return;
    if (sum[ind - 1] + s <= c)
    {
        ans = max(ans, sum[ind - 1] + s);
        return;
    }
    ans = max(ans, s);
    for (int i = 1; i < ind; i++)
        DFS(i, s + a[i]);
}
inline void solve(void)
{
    cin >> n >> c;
    for (int i = 1; i <= n; i++)
        cin >> a[i], sum[i] = sum[i - 1] + a[i];
    DFS(n + 1, 0);
    cout << ans;
    return;
}
int main()
{
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    FastIO;
    int T;
    T = 1;
    while (T--)
        solve();

    return 0;
}

这是万紫千红代码:

#include <bits/stdc++.h>
#define USED(VAL) VAL++, VAL--
#define Max (MaxNum - 7)
#define INF 0x3f3f3f3f
#define FastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define max(a, b) (a < b ? b : a)
#define min(a, b) (a < b ? a : b)
#define Endl cout << "\n"
#define endl '\n'

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;
typedef long double LD;

const int MaxNum = 1000 + 7;

/*The function of the code was {the functions and ideas...}*/

/*Functions...*/
LL sum[MaxNum], a[MaxNum], ans, n, c;
inline void DFS(int ind, LL s)
{
    if (s > c)
        return;
    if (sum[ind] + s <= c)
    {
        ans = max(ans, sum[ind] + s);
        return;
    }
    ans = max(ans, s);
    for (int i = 1; i <= ind; i++)
        DFS(i, s + a[i]);
}
inline void solve(void)
{
    cin >> n >> c;
    for (int i = 1; i <= n; i++)
        cin >> a[i], sum[i] = sum[i - 1] + a[i];
    DFS(n, 0);
    cout << ans;
    return;
}
int main()
{
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    FastIO;
    int T;
    T = 1;
    while (T--)
        solve();

    return 0;
}

这是为什么啊啊啊啊

2024/8/16 11:52
加载中...