HDU 4045 Machine scheduling (combinatorial math-Stirling number, combinatorial math-permutation combination)

Source: Internet
Author: User

Machine scheduling
Time limit:5000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)Total Submission (s): Accepted submission (s): 363

Problem Descriptiona Baidu ' s engineer needs to analyze and process large amount of data on machines every day. The machines is labeled from 1 to N. On all day, the engineer chooses R machines to process data. He allocates the R machines to no more than M groups, and if the difference of 2 machines ' labels is less than k,they can Not work on the same day. Otherwise the machines won't work properly. That's to say, the machines labeled with 1 and k+1 can work in the same day while those labeled with 1 and K should not W Ork in the same day. Due to some unknown reasons, the engineer should isn't choose the allocation scheme the same as that on some previous day. Otherwise all the machines need to be initialized again. As you know, the initialization would take a long time and a lot of efforts. Can-you-tell the engineer-the-maximum days, the He can use these machines continuously without re-initialization.

Inputinput End With EOF.
Input would be a four integers n,r,k,m.we assume that they is all between 1 and 1000.

Outputoutput the Maxmium days modulo 1000000007.

Sample Input
5 2 3 2

Sample Output
6HintSample input means you can choose 1 and 4,1 and 5,2 and 5 in the same day. And you can make the machines in the same group or the different group.  Got 6 schemes.1 and 4 in same group,1 and 4 in different groups.1 and 5 in same group,1 and 5 in different groups.2 and 5 in same group,2 and 5 in different groups. We assume 1 in a group and 4 in B group are the same as 1 in B group and 4 in a group.

Sourcethe 36th ACM/ICPC Asia regional Beijing site--online Contest
Recommendlcy | We have carefully selected several similar problems for you:4049 4047 4050 4048 4042
Problem Solving Ideas:

This is a combination of permutations.

(1) First, the N element number 1~n to select the R element, so that any two element number is different >=k

Solution: First according to 1 k+1 2*k+1 .... (r-1) *k+1 is exactly the interval K-permutation down

So a total of n elements, the remaining n (r-1) *k-1 elements can be considered as spaces, very space, they are inserted into the r+1 of the R element in a neutral,

This guarantees the enumeration of the number of methods that are known, and the requirement to meet any two element number difference >=k

So the problem is reduced to: assigning space elements to r+1 zones, which can be empty

The answer is: stir2[space][r+1], the second kind of Stirling number


(2) Then, the selected R elements are divided into no more than G Group, enumerate the desired number of groups can be

Only need to enumerate the corresponding number of groups, 1~min (R,G)

Conversion problem: N elements can be divided into M-sets, NOT NULL scheme method, the method of inserting plates, the answer is: c[n+m-1][m-1]


Problem Solving Code:

#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include < Algorithm>using namespace Std; typedef long LONG ll;const ll mod=1000000007;const int Maxn=1010;int n,r,m,g; ll C[2*MAXN][2*MAXN],STIR2[MAXN][MAXN];        void Ini () {for (int i=1;i<2*maxn;i++) {c[i][0]=c[i][i]=1;    for (int j=1;j<i;j++) c[i][j]= (c[i-1][j-1]+c[i-1][j])%mod;        } for (int i=1;i<maxn;i++) {stir2[i][0]=0;        Stir2[i][i]=1;    for (int j=1;j<i;j++) stir2[i][j]= ((LL) j*stir2[i-1][j]+stir2[i-1][j-1])%mod;    }} ll Get1 (ll n,ll m) {//n elements can be divided into a maximum of M-sets, NOT NULL scheme method. return c[n+m-1][m-1];}    ll Get2 (ll n,ll m) {//n elements are assigned to M-regions and can be empty.   return stir2[n][m];}    void Solve () {int space=n-(r-1) *m-1;        if (space<0) {printf ("0\n");    return;    } ll Ans=0;    Divide r elements into Group I for (int i=1;i<=min (R,G); i++) {ans= (Ans+get2 (r,i))%mod;    } ans= (Ans*get1 (space,r+1))%mod; Cout<<ans<<endl;} int main () {ini ();    while (scanf ("%d%d%d%d", &n,&r,&m,&g)!=eof) {solve (); } return 0;}



HDU 4045 Machine scheduling (combinatorial math-Stirling number, combinatorial math-permutation combination)

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.