1201 integer Dividing base time limit: 1 seconds space limit: 131072 KB score: 80 Difficulty: 5 level algorithm The question divides n into several different integers, and how many different ways are divided, for example: n = 6,{6} {1,5} {2,4} {three-way}, a total of 4. Due to the large data, output mod 10^9 + 7 results. Input
Enter 1 number n (1 <= n <= 50000).
Output
Output divided by the number mod 10^9 + 7.
Input example
6
Output example
4
Analysis: The key to this problem is different integers
A division with the largest number must be 1+2+3+....+m = = N
This way (M + 1) * M <= 2 * n
You can determine if M is O (sqrt (n)) level
It is easy to think of the number of divisions in which the number of numbers divided into J is represented by Dp[i][j].
Equation: dp[i][j] = Dp[i-j][j] + dp[i-j][j-1]
The former indicates that the I-J is divided into J number, and each number plus 1 is the scheme that I divide into J number.
But the former is so i-j that the scheme of +1 to form I is divided into J number of schemes is incomplete, because no 1
The latter complements this part of the answer, indicating that the i-j is divided into J number, each number +1, and the scheme joins a 1 element.
Because the number is not repeated, the number of 1 can only be 1.
Still write these simple questions in Java.
1 Packagep1201;2 3 ImportJava.util.*;4 ImportJava.io.*;5 6 Public classMain7 {8 9 /**Ten * @paramargs One */ A Final Static intMOD = (int) 1e9 + 7; - Public Static voidMain (string[] args) - { the //TODO auto-generated Method Stub -Scanner reader =NewScanner (system.in); -PrintWriter writer =NewPrintWriter (System.out); - + intn =reader.nextint (); - intm = 0; + while((1 + m) * M/2 < N) m++; A at int[] DP =New int[n + 1] [M + 1]; -Dp[0][0] = 1; - for(inti = 1; I <= m; i++) - for(intj = (1 + i) * I/2; J <= N; J + +) - { -Dp[j][i] = (Dp[j-i][i] + dp[j-i][i-1])%MOD; in } - to intAns = 0; + for(inti = 1; I <= m; i++) -Ans = (ans + dp[n][i])%MOD; the writer.println (ans); * $ reader.close ();Panax Notoginseng Writer.flush (); - } the +}
View Code
51nod p1201 Integer Division