Enumerating FL, it becomes a problem of integer partitioning ... f (i,j) = f (i-j,j-1) +f (I-j,j)-F (i-n-1,j-1) recursion. F (i,j) indicates number I consists of j different numbers, and the maximum number of programs not exceeding N
--------------------------------------------------------------------------
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 10009;const int MAXK = n; int MOD, N, K;int F[MAXN * MAXK][MAXK];void upd (int &t, int d) {if ((t + = d) >= MOD)T-= MOD;}int main () {int T;scanf ("%d", &t);While (t--) {scanf ("%d%d%d", &n, &k, &mod);memset (f, 0, sizeof f);f[0][0] = 1;for (int i = 1, lim = N * K; i < Lim; i++)For (int j = 1; J <= min (i, K); j + +) {F[i][j] = f[i-j][j-1] + f[i-j][j];if (i > N)F[i][j]-= f[i-n-1][j-1];F[i][j] + = MOD;While (F[i][j] >= MOD)F[i][j]-= MOD;}int ans = 0;for (int i = 1, lim = N * K; i < Lim; i++)For (int j = 1; j < K; J + +) {upd (ans, f[i][j] * f[i][k-j]% MOD);if (J > 1)upd (ans, f[i][j-1] * f[i][k-j]% MOD);}if (K = = 1)ans = 1;printf ("%d\n", ans);}return 0;}
--------------------------------------------------------------------------
3612: [Heoi2014] Balance time limit: ten Sec Memory Limit:
Submit: 173 Solved: 126
[Submit] [Status] [Discuss]
Description class, Lulu, Flower Xuanxuan on the desk with three prism teaching aids and ruler put up a "seesaw." This "seesaw" structure is this: the bottom is a side parallel to the ground plane of the three prism teaching aids, a ruler is placed on the ruler, a number of the same rubber. The ruler has 2n + 1 equidistant tick marks, and the nth + 1 tick marks are exactly at the center of the ruler, and coincide completely with the edges of the three prism that are not on the desk. Lulu found the seesaw to be unbalanced (the ruler was uneven in the ground plane). So, she put a few rubber on the ruler, and moved a number of rubber position, so that the ruler of the 2n + 1 tick line is just a piece of the same quality of rubber. The seesaw was balanced, and Lulu was delighted. Flowers think this is too no meaning, so from the ruler took the K a rubber. What surprised her was that the ruler remained balanced! Xuan Xuan is a thoughtful child, she certainly does not have the ruler to maintain the balance is surprised, because this is only an accidental event. What interested her was how many ways to take the K-Eraser, so that the ruler remained balanced? Of course, in order to simplify the problem, she had to make some sacrifices-assuming that all erasers had the same mass of particles. But even so, she failed to figure out the number. After school, she gave the question to her brother/sister--hibarigasaki, who is the president of the School of learning, that is you. Of course, because the answer to this question may be too large, you just need to tell her the value of mod p for the answer. Input
The first line, a positive integer, represents the number of data sets T (the number of times you are asked).
Next T line, 3 positive integers per line n, K, p. Output
A total of T-lines, one positive integer per line, represents the answer to the corresponding question you have drawn.
Sample Input10
6 5 10000
4 1 10000
9 6 10000
4 6 10000
5 1 10000
8318 10 9973
9862 9 9973
8234 9 9973
9424 9 9973
9324 9 9973Sample Output73
1
920
8
1
4421
2565
0
446
2549HINT
T <= 20,1 <= n <= 10000,1 <= k <= 10,2 <= P <= 10000, and K <= 2n+1.
Source
Acknowledgement anonymous Upload
Bzoj 3612: [Heoi2014] Balance (DP)