动态规划:划分数 复习

#include <iostream>
#include <algorithm>
using namespace std;

const int maxn = 1000 + 20;
int n, m, M;
int dp[maxn][maxn];

/*
4
3
10000
*/
void solve()
{
    cin >> n >> m >> M;
    dp[0][0] = 1;
    //dp[i][j] = 存储着 j 的 i划分 
    for (int i = 1; i <= m; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            if (j - i >= 0) {
                dp[i][j] = (dp[i - 1][j] + dp[i][j - i]) % M;
            }
            else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    cout << dp[m][n] << endl;
}

int main()
{
    solve();
    
    return 0;
    
}
原文地址:https://www.cnblogs.com/douzujun/p/8525078.html