题目链接:https://vjudge.net/problem/HDU-4045

Machine scheduling

Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1907    Accepted Submission(s): 702

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

题意:

从1~n中选出r个数,要求这r个数之间每对数的差值大于等于k;选出之后,再将这r个数分成m组。问总共有多少种方案?

题解:

问题分为两个部分进行求解:

1.如果正确选出这r个数呢?

如图,O代表选出的r个数,双下划线代表相邻两个数之间的差值。由于数字从1开始,所以最左边应该填上1;由于相邻两个数之间差值最小为k,所以出于中间的下划线应该填上k,这样就满足题目的限定。还剩下 n-1-(r-1)*k,然后再把他们分到r+1个下划线上。根据隔板法,总共有 C[n-1-(r-1)*k+r+1-1][r+1-1] = C[n-1-(r-1)*k+r][r] 。

2.把r个数分成m组,就是第二类斯特林数了。注意r可能小于m, 所以应为 S[r][min(r,m)] 。

3.所以总的方案数为: C[n-1-(r-1)*k+r][r] * S[r][min(r,m)] 。

4.注意,当n<1+(r-1)*k时,即连最基本的条件都满足不了时,方案数为0,需要特判。

代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e3+; LL S[MAXN][MAXN], f[MAXN][MAXN], C[MAXN][MAXN]; void init()
{
for(int i = ; i<MAXN; i++)
{
C[i][] = ;
for(int j = ; j<=i; j++)
C[i][j] = (C[i-][j-]+C[i-][j])%MOD;
} for(int i = ; i<MAXN; i++)
{
S[i][] = ; S[i][i] = ;
for(int j = ; j<i; j++)
S[i][j] = ((j*S[i-][j])%MOD + S[i-][j-])%MOD;
} memset(f, , sizeof(f));
for(int i = ; i<MAXN; i++)
for(int j = ; j<=i; j++)
f[i][j] = (f[i][j-] + S[i][j])%MOD;
} int main()
{
init();
int n, r, k, m;
while(scanf("%d%d%d%d", &n,&r,&k,&m)!=EOF)
{
LL ans;
if(+(r-)*k>n) ans = ;
else ans = (1LL*C[n--(r-)*k+r][r]*f[r][min(r,m)])%MOD;
printf("%lld\n", ans);
}
}

HDU4045 Machine scheduling —— 隔板法 + 第二类斯特林数的更多相关文章

  1. 【hdu4045】Machine scheduling(dp+第二类斯特林数)

    传送门 题意: 从\(n\)个人中选\(r\)个出来,但每两个人的标号不能少于\(k\). 再将\(r\)个人分为不超过\(m\)个集合. 问有多少种方案. 思路: 直接\(dp\)预处理出从\(n\ ...

  2. 8-机器分配(hud4045-组合+第二类斯特林数)

    http://acm.hdu.edu.cn/showproblem.php?pid=4045 Machine schedulingTime Limit: 5000/2000 MS (Java/Othe ...

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

    题目链接:http://codeforces.com/gym/101147/problem/G 题意:n个人,去参加k个游戏,k个游戏必须非空,有多少种放法? 分析: 第二类斯特林数,划分好k个集合后 ...

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

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

  5. 【BZOJ4555】求和(第二类斯特林数,组合数学,NTT)

    [BZOJ4555]求和(第二类斯特林数,组合数学,NTT) 题面 BZOJ 题解 推推柿子 \[\sum_{i=0}^n\sum_{j=0}^iS(i,j)·j!·2^j\] \[=\sum_{i= ...

  6. CF932E Team Work(第二类斯特林数)

    传送门:CF原网 洛谷 题意:给定 $n,k$,求 $\sum\limits^n_{i=1}\dbinom{n}{i}i^k\bmod(10^9+7)$. $1\le n\le 10^9,1\le k ...

  7. HDU - 4625 JZPTREE(第二类斯特林数+树DP)

    https://vjudge.net/problem/HDU-4625 题意 给出一颗树,边权为1,对于每个结点u,求sigma(dist(u,v)^k). 分析 贴个官方题解 n^k并不好转移,于是 ...

  8. 【CF961G】Partitions 第二类斯特林数

    [CF961G]Partitions 题意:给出n个物品,每个物品有一个权值$w_i$,定义一个集合$S$的权值为$W(S)=|S|\sum\limits_{x\in S} w_x$,定义一个划分的权 ...

  9. 【CF932E】Team Work(第二类斯特林数)

    [CF932E]Team Work(第二类斯特林数) 题面 洛谷 CF 求\(\sum_{i=1}^nC_{n}^i*i^k\) 题解 寒假的时候被带飞,这题被带着写了一遍.事实上并不难,我们来颓柿子 ...

随机推荐

  1. javascript --- 继承小结

    回顾之前学到的知识,大体上可以分为两类: 1. 基于构造器工作的模式. 2. 基于对象的工作模式. 3. 是否使用原型 4. 是否执行属性拷贝. 5. 两者都有(执行原型属性拷贝) 下面我们把之前的知 ...

  2. javascript --- 构造器借用

    接下来我们在看一种继承的实现.这需要再次利用构造器函数入手,这回不直接使用对象了.由于在这种继承模式中,子对象构造器可以通过call()和apply()方法来调用父对象的构造器.因而可以被称作构造器盗 ...

  3. SpringMVC中 Controller的 @ResponseBody注解分析

    需求分析:需要 利用    out 对象返回给财付通是否接收成功 .那么将需要如下代码: /** * 返回处理结果给财付通服务器. * @param msg: Success or fail. * @ ...

  4. 临远的activiti教程

    1. 简介 协议 下载 源码 必要的软件 JDK 6+ Eclipse Indigo 和 Juno 报告问题 试验性功能 内部实现类 2. 开始学习 一分钟入门 安装Activiti 安装Activi ...

  5. Hibernate操作Blob数据

      首先看数据库.数据库中新建一个BlobTable表,表中有两个字段,一个id(主键)一个picture字段是Blob类型字段.然后使用Hibernate向该数据库中写入和读取数据 在POJO类中p ...

  6. CSRF攻击 & XSS攻击

    之前有几篇文章写了 SQL注入类问题: http://www.cnblogs.com/charlesblc/p/5987951.html (介绍) http://www.cnblogs.com/cha ...

  7. PS 基础知识 如何绘制几何图形

    注意:规则的几何图形必须用路径工具,如果使用简单的椭圆工具再描边,则效果是像素堆砌起来的.图像一旦放大就是出现明显的失真.   使用钢笔工具,然后选择路径工具,然后选择需要绘制的图形.   如果需要找 ...

  8. android:使用gallery和imageSwitch制作可左右循环滑动的图片浏览器

    为了使图片浏览器左右无限循环滑动 我们要自己定义gallery的adapter 假设要想自己定义adapter首先要了解这几个方法 @Override public int getCount() { ...

  9. redis cmd 使用样例

    Redis 命令參考 一 Redis介绍 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15 ...

  10. mysql 海量数据删除

    百度知道 - mysql删除海量数据   MySQL 数据库删除大批量数据的优化     看到这儿的话,最后看下这篇文章,对于操作海量数据的sql深入分析 cnblogs - 深度分析DROP,TRU ...