HDU 4045 machine Scheduling [DP + Stirling number]

Source: Internet
Author: User

Transmission Door

Machine scheduling

Time limit:5000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1048 Accepted Submission (s): 387


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 INPUT5 2 3 2

Sample OUTPUT6 HintSample 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.

Source the 36th acm/icpc Asia regional Beijing site--online Contest

Recommendlcy | We have a carefully selected several similar problems for you:4043 4047 4050 4048 4042 Test instructions: n machines, each day to elect R station, dividing it into no more than M-Group, required to select between the machines Number difference >=k, the choice of the day can not be the same as before, ask the maximum number of days. Puzzle: The R machine is divided into no more than M group, can be pre-treatment with Stirling number. The following is the number of solutions to select the R machine. Then Dp[i][j] said, select the number I of the machine, in [I,n] in the interval need to select the number of J machine scheme. SUM[I][J] Indicates the number of scenarios in the [I,n] range that need to be selected for the J machine. Then the transfer equation is: dp[i][j]=sum[i+k][j-1];sum[i][j]=sum[i+1][j]+dp[i][j];

13083183 2015-03-10 19:16:25 Accepted 4045 358MS 25380K 1461 B g++ Czy

1#include <cstdio>2#include <cstring>3#include <stack>4#include <algorithm>5 6 #definell Long Long7 int ConstN =1005;8llConstMoD =1000000007;9 Ten using namespacestd; One  A ll Stl[n][n]; - ll Sumstl; - ll N,r,k,m; the ll Dp[n][n]; - ll Sum[n][n]; - ll ans; -  + voidIni1 () - { +memset (STL,0,sizeof(STL)); A ll I; at      for(i=1; i<= +; i++){ -stl[i][i]=1; -     } -stl[0][0]=1; - ll P,j; -      for(p=1;p <= +;p + +){ in          for(j=1; j<=p;j++){ -Stl[p][j]= (j*stl[p-1][j]+stl[p-1][j-1])%MoD; to         } +     } -  the     //For (p=1;p<=10;p++) { *    //for (j=1;j<=p;j++) printf ("P=%i64d j=%i64d stl=%i64d\n", P,j,stl[p][j]); $    // }Panax Notoginseng } -  the voidINI () + { A ll I; theSumstl=0; +      for(i=1; i<=m;i++){ -Sumstl= (Sumstl+stl[r][i])%MoD; $     } $Memset (DP,0,sizeof(DP)); -memset (SUM,0,sizeof(sum)); -ans=0; the    //printf ("sumstl=%i64d\n", Sumstl); - }Wuyi  the voidSolve () - { Wu     inti,j; -      for(i=n;i>=1; i--){ Aboutdp[i][1]=1; $sum[i][1]= (sum[i+1][1]+dp[i][1])%MoD; -     } -      for(j=2; j<=r;j++){ -          for(i=n-k;i>=1; i--){ Adp[i][j]=sum[i+k][j-1]; +Sum[i][j]= (sum[i+1][J]+DP[I][J])%MoD; the         } -     } $Ans= (sum[1][R]*SUMSTL)%MoD; the } the  the void  out() the { -printf"%i64d\n", ans); in } the  the intMain () About { the     //freopen ("data.in", "R", stdin); the ini1 (); the      while(SCANF ("%i64d%i64d%i64d%i64d", &n,&r,&k,&m)! =EOF) +     { - ini (); the solve ();Bayi          out(); the     } the}

HDU 4045 machine Scheduling [DP + Stirling number]

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.