1 条题解

  • 0
    @ 2026-11-2 13:31:54

    双单调数组计数(Two Arrays) 题解

    思路分析

    按题目要求使用对应数据结构与算法模拟/递推求解,注意数据范围边界与时间复杂度。

    参考代码

    #include <iostream>
    #include <vector>
    using namespace std;
    
    const int MOD = 1000000007;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int n, m;
        if (!(cin >> n >> m)) return 0;
        int len = 2 * m;
        vector<int> dp(n + 1, 0);
        dp[1] = 1;
        for (int step = 1; step <= len; ++step) {
            for (int j = 2; j <= n; ++j) {
                dp[j] += dp[j - 1];
                if (dp[j] >= MOD) dp[j] -= MOD;
            }
        }
        long long ans = 0;
        for (int j = 1; j <= n; ++j) ans = (ans + dp[j]) % MOD;
        cout << ans << "\n";
        return 0;
    }
    
    • 1

    信息

    ID
    8707
    时间
    1000ms
    内存
    256MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者