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. javascript之IE版本检测

    近年来随着操作系统的升级以及各种新技术的开发普及,抛弃低版本IE已经是大势所趋,这对于前端人员来时是个好消息,可以不用花费太多的时间来做低版本的兼容,很多站点采用给予低版本IE以提示的方式(恩,很友好 ...

  2. 《构建之法》第8、9、10章 读书笔记和Sprint总结

    第八章:需求分析 这章主要解析了需求的多面方面,不同的项目需要不同的手段,真正的需求稍纵即逝,需要靠火眼金睛和敏捷的身手来发现并抓住它们.另外,很多时候用户并不知道自己确切的需求,或者不愿意表达完整的 ...

  3. ADO.NET学习系列(三)----做一个登录案例

    总体思路.根据用户输入的用户名和密码,来判断,和数据库里面存的是不是一样,如果一样就表明登录成功,否则就登录失败. 方案一: 1.select* from 表名 where username=&quo ...

  4. 后缀数组 --- WOj 1564 Problem 1564 - A - Circle

    Problem 1564 - A - Circle Problem's Link:   http://acm.whu.edu.cn/land/problem/detail?problem_id=156 ...

  5. 最新的SqlHelper 类

    最新的SqlHelper 类 摘自:http://www.cnblogs.com/sufei/archive/2010/01/14/1648026.html using System; using S ...

  6. [转]微信公众平台WeChat PHP SDK

    地址:https://github.com/dodgepudding/wechat-php-sdk 微信公众平台php开发包,细化各项接口操作,支持链式调用 微信支付接入文档: https://mp. ...

  7. FL2440驱动添加(5)ADC驱动学习笔记

    由图可知,模拟ADC分为两部分功能,一部分是触屏功能,另一部分就是普通ADC功能.分别可以产生INT_TC和INT_ADC 两个中断.该ADC模块总共有8个通道可以进行模拟信号的输入,分别是AIN0. ...

  8. 一个SpringMVC简单Demo中出现的错误

    最近在学springmvc 一个简答的Springmvc配置包括如下步骤: 1.在 web.xml 文件中配置 DispatcherServlet (该中央控制器相当于 MVC 模式中的 C),还可以 ...

  9. css导航栏

    几个导航栏也算对学过知识的回顾,总有新的收获,下面是学习过程中敲的代码: <!DOCTYPE HTML> <html> <head> <title>&l ...

  10. 3种 web 会话管理的方式

    转自:http://www.yidianzixun.com/n/0F1GYAsQ?s=8&appid=xiaomi&ver=3.7.8&utk=4lxc4q7c&fro ...