Codeforces 37D Lesson Timetable-combinatorial math-dynamic programming

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.