1 条题解

  • 0
    @ 2025-3-30 14:36:57

    大师

    #include <bits/stdc++.h>
    using namespace std;
    const int MOD = 998244353;
    const int BASE = 20000 + 5;
    int n;
    int a[1005];
    // dp[i][j]:以 a[i] 结尾,公差为 j 的子序列数量
    // 差在 -20000~20000 通过 +BASE 变换到了 -20000+BASE~20000+BASE 即 5~40005
    int dp[1005][40000 + 10];
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        // 输入
        cin >> n;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        // 记录答案
        int ans = 0;
        for (int i = 1; i <= n; i++)
        {
            ans++;                           // a[i] 自己这种方案记上
            for (int j = i - 1; j >= 1; j--) // 考虑前一个电塔是哪一个
            {
                // 如果接在 a[j] 后面构成一个子序列,公差就是 d=a[i]-a[j]
                int d = a[i] - a[j] + BASE;
                dp[i][d] = (dp[i][d] + (dp[j][d] + 1)) % MOD;
                ans = (ans + (dp[j][d] + 1)) % MOD;
            }
        }
        cout << ans << "\n";
        return 0;
    }
    

    信息

    ID
    1822
    时间
    1000ms
    内存
    500MiB
    难度
    4
    标签
    递交数
    9
    已通过
    5
    上传者