1 条题解

  • 0
    @ 2023-5-13 11:51:00
    #include <bits/stdc++.h>
    using namespace std;
    int n, m;
    int a[105];
    int sum[105];
    int f[105][105][10];
    int g[105][105][10];
    int cal(int x)
    {
        return (x % 10 + 10) % 10;
    }
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin >> n >> m;
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
            a[i + n] = a[i];
        }
        for (int i = 1; i <= 2 * n; i++)
            sum[i] = sum[i - 1] + a[i];
        for (int l = 0; l <= 2 * n; l++)
            for (int r = 0; r <= 2 * n; r++)
                f[l][r][0] = g[l][r][0] = 1;
        for (int len = 1; len <= n; len++)
        {
            for (int l = 1; l + len - 1 <= 2 * n; l++)
            {
                int r = l + len - 1;
                for (int k = 1; k <= min(len, m); k++)
                {
                    if (k == 1)
                    {
                        f[l][r][k] = g[l][r][k] = cal(sum[r] - sum[l - 1]);
                        continue;
                    }
                    f[l][r][k] = -1;
                    g[l][r][k] = 0x3f3f3f3f;
                    // 最后last个数成一份
                    for (int last = 1; last <= len - (k - 1); last++)
                    {
                        f[l][r][k] = max(f[l][r][k],
                                         (f[l][r - last][k - 1] * cal(sum[r] - sum[r - last])));
                        g[l][r][k] = min(g[l][r][k],
                                         (g[l][r - last][k - 1] * cal(sum[r] - sum[r - last])));
                    }
                }
            }
        }
        int ansMax = -1;
        int ansMin = -1;
        for (int l = 1; l + n - 1 <= 2 * n; l++)
        {
            int now = f[l][l + n - 1][m];
            if (ansMax == -1 || now > ansMax)
                ansMax = now;
            now = g[l][l + n - 1][m];
            if (ansMin == -1 || now < ansMin)
                ansMin = now;
        }
        cout << ansMin << "\n"
             << ansMax << "\n";
        return 0;
    }
    
    • 1

    信息

    ID
    84
    时间
    1000ms
    内存
    128MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者