3 条题解

  • 0
    @ 2023-3-11 10:32:39
    备注:
    ******************************************/
    #include <queue>
    #include <math.h>
    #include <stack>
    #include <stdio.h>
    #include <iostream>
    #include <vector>
    #include <iomanip>
    #include <string.h>
    #include <algorithm>
    #include <map>
    using namespace std;
    #define int long long
    const int N = 1e3 + 10;
    const int INF = 0x3f3f3f3f;
    int n;
    int a[N];
    int dp[N][N][41];
    void calc(int t[], int s)
    {
    int k = 0;
    for(int i = 0; i < 40; i++)
    {
    t[i] = t[i] * s + k;
    k = t[i] / 10;
    t[i] %= 10;
    }
    }
    void add(int t[], int dp[])
    {
    for(int i = 0; i < 40; i++)
    {
    t[i] += dp[i];
    t[i+1] += t[i] / 10;
    t[i] %= 10;
    }
    }
    bool cmp(int t[], int dp[])
    {
    for(int i = 40; i >= 0; i--)
    {
    if(t[i] > dp[i])
    return false;
    else if(t[i] < dp[i])
    return true;
    }
    return false;
    }
    void print(int dp[])
    {
    int k = 40;
    while(dp[k] == 0)
    k--;
    for(int i = k; i >= 0; i--)
    {
    cout << dp[i];
    }
    cout << endl;
    }
    signed main()
    {
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
    cin >> a[i];
    }
    for(int k = 3; k <= n; k++)
    {
    for(int l = 1; l <= n-k+1; l++)
    {
    int r = l+k-1;
    dp[l][r][40] = 1;
    for(int i = l+1; i < r; i++)
    {
    int t[41];
    memset(t, 0, sizeof(t));
    t[0] = 1;
    calc(t, a[i]);
    calc(t, a[l]);
    calc(t, a[r]);
    add(t, dp[l][i]);
    add(t, dp[i][r]);
    if(cmp(t, dp[l][r]))
    memcpy(dp[l][r], t, sizeof(t));
    }
    }
    }
    print(dp[1][n]);
    return 0;
    }
    

    信息

    ID
    468
    时间
    1000ms
    内存
    512MiB
    难度
    6
    标签
    递交数
    146
    已通过
    50
    上传者