Machine scheduling


Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1000    Accepted Submission(s): 363

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
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  4049 4047 4050 4048 4042 
 

解题思路:

这题考的是排列组合

(1)首先,要从n个元素编号1~n中选出r个元素来,使得任意两个元素编号相差>=k

解法:先按照 1 k+1 2*k+1 .... (r-1)*k+1 也就是刚好 间隔 k个排列下来

那么 总共n个元素,剩余 n-(r-1)*k-1个元素可以看成空格,极为space,将它们插入这r个元素的r+1个空档中,

这样就能保证枚举了素有的方法数,切满足任意两个元素编号相差>=k的要求

所以这个问题简化为:将space个元素分配到r+1个区域中,可以为空

答案为:stir2[space][r+1],第二类斯特林数

(2)然后,再将选取的r个元素分为不超过g组,枚举想要的组数即可

只需要枚举对应的组数, 1~min(r,g)

转化问题:将n个元素最多分为m个集合,不为空的方案法,插板法,答案为:c[n+m-1][m-1]

解题代码:

#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个元素最多分为m个集合,不为空的方案法。
return c[n+m-1][m-1];
} ll get2(ll n,ll m){//将n个元素分配到m个区域中,可以为空。
return stir2[n][m];
} void solve(){
int space=n-(r-1)*m-1;
if(space<0){
printf("0\n");
return ;
}
ll ans=0;
//将r个元素分为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;
}

版权声明:欢迎关注我的博客,本文为博主toyking原创文章,未经博主允许不得转载。

HDU 4045 Machine scheduling (组合数学-斯特林数,组合数学-排列组合)的更多相关文章

  1. hdu 4045 Machine scheduling [ dp + 斯特林数]

    传送门 Machine scheduling Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  2. HDU 4045 Machine scheduling --第二类Strling数

    题意: n个数(1~n)取出r个数,取出的数相差要>=k, 然后分成m个可空组,问有多少种情况. 解法: 先看从n个数中取r个相差>=k的数的方法数,可以发现 dp[i][j] = dp[ ...

  3. BZOJ4559 JLOI2016成绩比较(容斥原理+组合数学+斯特林数)

    容斥一发改为计算至少碾压k人的情况数量,这样对于每门课就可以分开考虑再相乘了.剩下的问题是给出某人的排名和分数的值域,求方案数.枚举出现了几种不同的分数,再枚举被给出的人的分数排第几,算一个类似斯特林 ...

  4. P6620-[省选联考2020A卷]组合数问题【组合数学,斯特林数】

    正题 题目链接:https://www.luogu.com.cn/problem/P6620 题目大意 给出\(n,x,p,m\)和一个\(m\)次多项式\(f\)求 \[\sum_{k=0}^nf( ...

  5. bzoj 2159 Crash 的文明世界 && hdu 4625 JZPTREE ——第二类斯特林数+树形DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2159 学习材料:https://blog.csdn.net/litble/article/d ...

  6. hdu 2643 rank 第二类斯特林数

    题意:给定n个人,要求这n个人的所有可能排名情况,可以多个人并列(这个是关键). 题解:由于存在并列的问题,那么对于n个人,我们最多有n个排名,枚举一下1~n,累加一下就好.(注意这里是变种的斯特林数 ...

  7. 蓝桥杯 问题 1110: 2^k进制数 (排列组合+高精度巧妙处理)

    题目链接 题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2 ...

  8. 【noi 2.6_9288】&【hdu 1133】Buy the Ticket(DP / 排列组合 Catalan+高精度除法)

    题意:有m个人有一张50元的纸币,n个人有一张100元的纸币.他们要在一个原始存金为0元的售票处买一张50元的票,问一共有几种方案数. 解法:(学习了他人的推导后~) 1.Catalan数的应用7的变 ...

  9. bzoj 2159 Crash 的文明世界 & hdu 4625 JZPTREE —— 第二类斯特林数+树形DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2159 使用公式:\( n^{k} = \sum\limits_{i=0}^{k} S(k,i ...

随机推荐

  1. 12 19 spring3 项目总结

    项目截图: 林集团 https://home.cnblogs.com/u/linjituan/ 团队guihub: https:///github.com/MoiGi 李鹏飞 https://www. ...

  2. List<?>和List<T>的区别?

    出自:https://www.zhihu.com/question/31429113

  3. 微软开源的30个基础设施项目-C#

    .NET Compiler Platform ("Roslyn") .NET Core 5 .NET Micro Framework .NET SDK For Hadoop ASP ...

  4. OracleHelper(对增删改查分页查询操作进行了面向对象的封装,对批量增删改操作的事务封装)

    公司的一个新项目使用ASP.NET MVC开发,经理让我写个OracleHelper,我从网上找了一个比较全的OracleHelper类,缺点是查询的时候返回DataSet,数据增删改要写很多代码(当 ...

  5. 如何选择RabbitMQ的消息保存方式?

    RabbitMQ对于queue中的message的保存方式有两种方式:disc和ram.如果采用disc,则需要对exchange/queue/delivery mode都要设置成durable模式. ...

  6. mybatis 下划线转驼峰配置

    一直以来,在sqlmap文件中,对于数据库中的下划线字段转驼峰,我们都是通过resultmap来做的,如下: <resultMap id="ISTableStatistics" ...

  7. SharpGL学习笔记(十二) 光源例子:解决光源场景中的常见问题

    笔者学到光源这一节,遇到的问题就比较多了,收集了一些如下所述: (1) 导入的3ds模型,如果没有材质光照效果很奇怪.如下图 (2) 导入的3ds模型,有材质,灯光效果发暗,材质偏色,效果也很奇怪. ...

  8. mac下eclipse的svn(即svn插件)怎么切换账号?

    以mac os x为例(Unix/Linux类似) 打开命令行窗口,即用户的根目录(用户的home目录) cd ~ 即可进入home目录. 执行命令 ls -al 会列出home目录下的所有文件及文件 ...

  9. Jaxb解析xml准换为javabean

    先说下这个的背景吧,前些日子,有个以前的小同事说刚接触webservice,想解析下xml,记得我学的时候还是dom4j,sax的解析方式,最近看别人的代码用的jaxb的方式,觉得注解起来很简练,所以 ...

  10. linux 查看占用内存/CPU最多的进程

    可以使用一下命令查使用内存最多的5个进程 ps -aux | sort -k4nr | head -n 5 或者 top (然后按下M,注意大写) 可以使用一下命令查使用CPU最多的5个进程 ps - ...