http://acm.hdu.edu.cn/showproblem.php?pid=4045
Machine scheduling
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1933 Accepted Submission(s): 711
Problem Description
A Baidu’s engineer needs to analyze and process large amount of data on machines every day. The machines are labeled from 1 to n. On each 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 are less than k,they can not work in the same day. Otherwise the two machines will not work properly. That is 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 work in the same day. Due to some unknown reasons, the engineer should not 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 will take a long time and a lot of efforts. Can you tell the engineer the maximum days that he can use these machines continuously without re-initialization.
Input
Input end with EOF.
Input will be four integers n,r,k,m.We assume that they are all between 1 and 1000.
Output
Output the maxmium days modulo 1000000007.
Sample Input
5 2 3 2
Sample Output
6
Hint
Sample 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 in the different group.
So you 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 is the same as 1 in b group and 4 in a group.
Source
The 36th ACM/ICPC Asia Regional Beijing Site —— Online Contest
Recommend
lcy | We have carefully selected several similar problems for you: 4043 4049 4046 4041 4047
题意:有N个机器,每天选出R个机器,而且每两个机器的编号差要大于等于K,每天将这R个机器最多分为M组工作,问最多有多少种方案。
思路:问题由两部分构成:第一,从N个机器中选出R个满足条件的机器的方案数;第二,将R个机器最多分为M组有的方案数。二者乘积即为答案。
第一部分:
先满足每两个机器之间至少有K-1个间隔,也就是还剩下rem=n-((r-1)*k+1)个机器可以随意安排,把这些多余的插入到R个机器之间(加上两端共R+1个位置)。问题也就变为rem个相同的球分到R+1个不同的组可以为空这种模型,不难推出是C(rem+R,R),网上有说直接用插板法公式。可参考:插板法
因为选出的r个机器是相对固定的,考虑其他情况是就要考虑剩余的rem个的处理,保持间隔大于等于k就行,也就是说原来选的数列中间可以在插入剩余的数,间隔有r + 1 个,故相当于将剩下的分为r+1分放入,即插入r块板子,但可以插入空,即相当于分成的份数是小于等于r+1的,所以是板子是1, 2,... r;则种类有:C(ren + 1, 1) + C(ren + 1, 2) +...+C(ren + 1, r) = C(ren + r, r) ==》利用的是:C(n - 1, m - 1) + C(n - 1, m) = C(n , m)
第二部分:R个元素分为i个非空集合是第二类斯特林数,对i为1至m求和即可。
第二类Stirling数 ( https://baike.baidu.com/item/%E6%96%AF%E7%89%B9%E6%9E%97%E6%95%B0/4938529?fr=aladdin )
定义
![](https://gss0.bdstatic.com/-4o3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D51/sign=bd7e0b6dcb11728b342d8c23c9fc647a/1c950a7b02087bf466afd315f4d3572c10dfcf8f.jpg)
![](https://gss0.bdstatic.com/-4o3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D44/sign=45ffc73c84025aafd7327fcff9ed5ae9/eaf81a4c510fd9f943c6d495232dd42a2934a47d.jpg)
![](https://gss1.bdstatic.com/-vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D243/sign=f515d458a118972ba73a07ced5cd7b9d/b21bb051f8198618137907c840ed2e738bd4e644.jpg)
递推式
![](https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D73/sign=80d804f28194a4c20e23e5280ff4794d/a8ec8a13632762d0a1534142a6ec08fa503dc6da.jpg)
![](https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D261/sign=9ff76854af014c081d3b2fa33b79025b/0d338744ebf81a4c27dc0934d12a6059242da665.jpg)
性质
![](https://gss2.bdstatic.com/-fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D81/sign=b8b1b6fbaaaf2eddd0f144e88c10d336/d788d43f8794a4c2b3a62fd608f41bd5ac6e3942.jpg)
![](https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D72/sign=5329baddbf12c8fcb0f3f4cffd03611c/0b7b02087bf40ad1437b0f1e512c11dfa8ecceb4.jpg)
![](https://gss2.bdstatic.com/9fo3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D72/sign=7cebeef55543fbf2c12ca421b17ec736/c8177f3e6709c93dca78c50a993df8dcd0005441.jpg)
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
int c[2005][2005];
ll s[1004][1005]; //这里用int就wa!!!
ll mod = 1e9+7;
ll cjj(int n, int r){ //递归求阶乘
if(c[n][r] != 0){
return c[n][r];
}
if(r == 0)
return c[n][r] = 1;
if(n == 0 || n < r)
return c[n][r] = 0;
if(r == n)
return c[n][r] = 1;
return c[n][r] = (cjj(n - 1, r) + cjj(n - 1, r - 1)) % mod;
}
ll sitelin(int n, int m){ //第二类斯特林数
if(s[n][m] != 0){
return s[n][m];
}
if(m == 0)
return s[n][m] = 1;
if(m == 1)
return s[n][m] = 1;
if(n == m)
return s[n][m] = 1;
if(n < m)
return s[n][m] = 0; //注意
return s[n][m] = (sitelin(n - 1, m - 1) + sitelin(n - 1, m) * m) % mod;
}
void init(){
for(int i = 0; i <= 1000; i++){
for(int j = 0; j <= 1000; j++){
cjj(i, j);
}
}
for(int i = 0; i <= 1000; i++){
for(int j = 0; j <= 1000; j++){
sitelin(i, j);
}
}
}
//void init ()
//{
// int i, j;
// for (i=1;i<=2000;i++) //递推求
// {
// c[i][0] = c[i][i]=1;
// for (j=1;j<i;j++)
// c[i][j] = (c[i-1][j-1] + c[i-1][j]) % mod;
// }
// for (i = 1; i <= 1000; i++){
// s[i][0] = 0;
// s[i][i] = 1;
// for(j = 1; j < i; j++) // <= WA
// s[i][j] = (s[i-1][j-1] + j * s[i-1][j]) % mod;
// }
//}
int main(){
int n, r, k, m;
init();
while(scanf("%d%d%d%d", &n, &r, &k, &m) != EOF){
ll sum = 0;
int ren = n - ((r - 1) * k + 1);
if(ren < 0){ //必须单独考虑不满足的情况
printf("0\n");
continue;
}
for(int i = 1; i <= m; i++){
sum = (sum + s[r][i]) % mod;
}
printf("%lld\n", sum * c[ren + r][r] % mod);
}
return 0;
}