Topic Portal
The Magical Door I
The Magical Door II
Main topic
There are $n$ group students to Class 2 times, there are $m$ classrooms, numbered $1$ to $m$. To determine how many different classes of classrooms are arranged (each group of students are essentially different), make them meet:
- The class number for the first class of each group of students is less than the number of the classroom that is equal to the second class.
- $i$ classroom in the first class, there happened to be a $x_{i}$ group of students present.
- $i$ classroom in a class, the middle of the student group can not exceed the number of $y_{i}$.
Output answer modulo $10^{9} + 7$.
Because the first class exactly how many people, so this program number can be directly used in combination number, can be thrown away for the time being.
For the second class, consider using dynamic planning to do, with $f[i][j]$, taking into account the first $i$ classrooms, there are currently $j$ individuals do not assign classrooms.
When transferring, enumerate the number of classes in the $i$ class, then multiply the number by the combination.
Code
1 /**2 * Codeforces3 * problem#37d4 * Accepted5 * Time:46ms6 * memory:6388k7 */8#include <bits/stdc++.h>9 using namespacestd;Ten One Const intN =1005, M = the, mod = 1e9 +7; A - intn =0, M; - intXs[m], ys[m]; the intC[n][n]; - intF[m][n]; - -Inlinevoidinit () { +scanf"%d", &m); - for(inti =1; I <= m; i++) +scanf"%d", XS + i), n + =Xs[i]; A for(inti =1; I <= m; i++) atscanf"%d", Ys +i); - } - -Inlinevoidsolve () { -c[0][0] =1; - for(inti =1; I <= N; i++) { inc[i][0] = C[i][i] =1; - for(intj =1; J < I; J + +) toC[I][J] = (C[i-1][j-1] + c[i-1][J])%MoD; + } - the ints =0, ans; *f[0][0] =1; $ for(inti =1; I <= m; i++) {Panax Notoginsengs + =Xs[i]; - for(intj = Xs[i]; J <= S; J + +) the for(intK =0; K <= J && K <= Ys[i]; k++) +F[i][j-k] = (F[i][j-k] + f[i-1][j-xs[i]] * 1LL * c[j][k])%MoD; A } theAns = f[m][0]; + for(inti =1; I <= m; i++) { -Ans = (ans * 1ll * c[n][xs[i])%MoD; $N-=Xs[i]; $ } -printf"%d\n", ans); - } the - intMain () {Wuyi init (); the solve (); - return 0; Wu}
Codeforces 37D Lesson Timetable-combinatorial math-dynamic programming