Article Directory
Subject to the effect
Problem-solving ideas
Such problems are generally referred to as the division. Note that this is classified asless than m equalparts, the use of dynamic programming solution.
- definition: : 's total number of splits.
- Target state: .
- State transition:
- Wrong idea: that the demand
's
When the division, from
in Naqu
a, then seek
's
division, that is,
- Error point: will and considered as different divisions.
- The right idea: for
's
division, there are two cases: (1) In order to exactly divide
parts. (2): For less than partitioning
parts.
- In the first case: We want to take away from every which are a result of the original and the result is one to one. Therefore, a total of
- Second case: direct correspondence is
. Thus eventually
- Wrong idea: that the demand
's
When the division, from
in Naqu
a, then seek
's
division, that is,
- Update Policy: dependent on the left of and above , According to line by line so the update cycle.
- Initial state: : i.e., when no article is divided into only a method that 0 parts.
- Note: In the transfer process, there will be such a situation, such as if it is not realistic, because he represents 2-division two items actually there is a. This is because we have takentake the equivalentof strategy, this status will only be cited. Therefore must without affecting other values.
- the complexity:
Code
#include<iostream>
using namespace std;
const int MAX = 1005;
int dp[2][MAX];
int main()
{
int m, n;
cin >> n >> m;
int M;
cin >> M;
dp[0][0] = 1;
for(int i=1; i<=m; i++)
{
for(int j=0; j<=n; j++)
{
if(j-1 >= 0)
dp[i%2][j] = (dp[1-i%2][j] + dp[i%2][j-i]) % M;
else
dp[i%2][j] = dp[1-i%2][j];// 当总数j小于划分数i时,不可能每一份都大于0
}
}
cout << dp[m%2][n] << endl;
}