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数实际上是集合的一个拆分,表示将n个不同的元素拆分成m个集合的方案数,记为

  

或者

  

。和第一类Stirling数不同的是,集合内是不考虑次序的,而圆排列是有序的。常常用于解决组合数学中几类放球模型。描述为:将n个不同的球放入m个无差别的盒子中,要求盒子非空,有几种方案?

第二类Stirling数要求盒子是无区别的,所以可以得到其方案数公式:

递推式

第二类Stirling数的推导和第一类Stirling数类似,可以从定义出发考虑第n+1个元素的情况,假设要把n+1个元素分成m个集合则分析如下:
(1)如果n个元素构成了m-1个集合,那么第n+1个元素单独构成一个集合。方案数  。
(2)如果n个元素已经构成了m个集合,将第n+1个元素插入到任意一个集合。方案数 m*S(n,m) 。
综合两种情况得:

  

性质

 

 

 
 
#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;
}

  

8-机器分配(hud4045-组合+第二类斯特林数)的更多相关文章

  1. 【cf961G】G. Partitions(组合意义+第二类斯特林数)

    传送门 题意: 给出\(n\)个元素,每个元素有价值\(w_i\).现在要对这\(n\)个元素进行划分,共划分为\(k\)组.每一组的价值为\(|S|\sum_{i=0}^{|S|}w_i\). 最后 ...

  2. 【BZOJ5093】图的价值(第二类斯特林数,组合数学,NTT)

    [BZOJ5093]图的价值(第二类斯特林数,组合数学,NTT) 题面 BZOJ 题解 单独考虑每一个点的贡献: 因为不知道它连了几条边,所以枚举一下 \[\sum_{i=0}^{n-1}C_{n-1 ...

  3. HDU2643(SummerTrainingDay05-P 第二类斯特林数)

    Rank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  4. bzoj 5093 [Lydsy1711月赛]图的价值 NTT+第二类斯特林数

    [Lydsy1711月赛]图的价值 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 245  Solved: 128[Submit][Status][D ...

  5. bzoj 5093 图的价值 —— 第二类斯特林数+NTT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=5093 每个点都是等价的,从点的贡献来看,得到式子: \( ans = n * \sum\li ...

  6. BZOJ 5093: [Lydsy1711月赛]图的价值 第二类斯特林数+NTT

    定义有向图的价值为图中每一个点的度数的 \(k\) 次方之和. 求:对于 \(n\) 个点的无向图所有可能情况的图的价值之和. 遇到这种题,八成是每个点单独算贡献,然后累加起来. 我们可以枚举一个点的 ...

  7. BZOJ5093 图的价值——推式子+第二类斯特林数

    原题链接 题解 题目等价于求这个式子 \[ans=n2^{\frac{(n-1)(n-2)}{2}}\sum\limits_{i=0}^{n-1}\binom{n-1}{i}i^k\] 有这么一个式子 ...

  8. Codeforces 932 E Team Work ( 第二类斯特林数、下降阶乘幂、组合数学 )

    题目链接 题意 : 其实就是要求 分析 : 先暴力将次方通过第二类斯特林数转化成下降幂 ( 套路?) 然后再一步步化简.使得最外层和 N 有关的 ∑ 划掉 这里有个技巧就是 将组合数的表达式放到一边. ...

  9. Gym 101147G 第二类斯特林数

    大致题意: n个孩子,k场比赛,每个孩子至少参加一场比赛,且每场比赛只能由一个孩子参加.问有多少种分配方式. 分析: k>n,就无法分配了. k<=n.把n分成k堆的方案数乘以n的阶乘.N ...

随机推荐

  1. Js中常用的字符串,数组,函数扩展

    由于最近辞职在家,自己的时间相对多一点.所以就根据prototytpeJS的API,结合自己正在看的司徒大神的<javascript框架设计>,整理了下Js中常用一些字符串,数组,函数扩展 ...

  2. Apache的下载安装(主要说的 64位)及问题

    本文转载自:http://blog.csdn.net/qq_15096707/article/details/47319545 今天重装完win10系统,就重新下载安装 Apache.虽说之前有安装过 ...

  3. Java并发-Runnable、Callable、Future、Future Task

    Runnable: Runnable的代码非常简单,他是一个接口,且接口中只有一个方法,run(),创建一个类实现他,把一些费时操作写在其中,然后使用某个线程去执行该Runnable实现类即可实现多线 ...

  4. 阻塞队列之三:SynchronousQueue同步队列 阻塞算法的3种实现

    一.SynchronousQueue简介 Java 6的并发编程包中的SynchronousQueue是一个没有数据缓冲的BlockingQueue,生产者线程对其的插入操作put必须等待消费者的移除 ...

  5. 【学步者日记】UnityEditor扩展菜单以及ScriptableObject

    完整版链接:http://note.youdao.com/noteshare?id=c54f35ca19371886e6a94302387bb6cd 下面是预览的部分,带图的版本请看上面链接.     ...

  6. 20181104_C#线程之Thread_ThreadPool_使用Thread实现回到和带参数的回调

    C#   .net  Framework多线程演变路径: 1.0    1.1 时代使用Thread 2.0    时代使用ThreadPool 3.0    时代使用Task 4.0    时代使用 ...

  7. linux oracle服务器无密码登录dba

    1.su - oracle 切换到oracle 2.sqlplus sys/manger as sysdba 3.新建用户: create user username identified by pa ...

  8. 浅谈PHP面向对象编程(九、设计模式)

    9.0 设计模式 在编写程序时经常会遇到一此典型的问题或需要完成某种特定需求,设计模式就是针对这些问题和需求,在大量的实践中总结和理论化之后优选的代码结构编程风格,以及解决问题的思考方式. 设计模式就 ...

  9. Entity Framework API介绍 -- DbSet<>().Find()

    过去我们常常使用Where或First(FirstOrDefault)方法来查找对应的实体,比如: var query = context.CertInfoMakeDetails.ToList().W ...

  10. Protobuf3教程

    Protobuf3教程 https://blog.csdn.net/hulinku/article/details/80827018 Protobuf语言指南——.proto文件语法详解 https: ...