题目链接: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. POJ 3259 Wormholes 最短路+负环

    原题链接:http://poj.org/problem?id=3259 题意 有个很厉害的农民,它可以穿越虫洞去他的农场,当然他也可以通过道路,虫洞都是单向的,道路都是双向的,道路会花时间,虫洞会倒退 ...

  2. GitBook一个专注于帮助文档的工具

    官网:https://www.gitbook.com GitHub组织:https://github.com/gitbookio GitBook一个专注于帮助文档的工具,比如: 1.简单的左侧列表右侧 ...

  3. debug : 调试主进程启动的子进程

    http://blog.csdn.net/lostspeed/article/details/10109867

  4. 卸载ArcGISDesktop低版本程序遇到异常,如何完全卸载?

    [解决办法]:正常情况下,运行 ArcGIS for Desktop 光盘中的 “冲突检测”工具,会自动完全卸载低版本的ArcGIS 程序.如果遇到异常无法卸载(例如安装过非正式版软件),如下位置是A ...

  5. mysql读写分离的三种实现方式

    1 程序修改mysql操作类可以参考PHP实现的Mysql读写分离,阿权开始的本项目,以php程序解决此需求.优点:直接和数据库通信,简单快捷的读写分离和随机的方式实现的负载均衡,权限独立分配缺点:自 ...

  6. CUDA 实现JPEG图像解码为RGB数据

    了解JPEG数据格式的人应该easy想到.其对图像以8*8像素块大小进行切割压缩的方法非常好用并行处理的思想来实现.而其实英伟达的CUDA自v5.5開始也提供了JPEG编解码的演示样例.该演示样例存储 ...

  7. POJ3592 Instantaneous Transference 强连通+最长路

    题目链接: id=3592">poj3592 题意: 给出一幅n X m的二维地图,每一个格子可能是矿区,障碍,或者传送点 用不同的字符表示: 有一辆矿车从地图的左上角(0,0)出发, ...

  8. 非GUI模式下运行JMeter和远程启动JMeter

    JMeter是一款非常不错的免费开源压力测试工具,越来越多的公司在使用.不过,在使用过程中可能会存在一些问题,比如:GUI模式非常消耗资源,单个客户端测试无法达到目标压力.而使用非 GUI 模式,即命 ...

  9. (updated on Mar 1th)Programming Mobile Applications for Android Handheld Systems by Dr. Adam Porter

    本作品由Man_华创作,采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可.基于http://www.cnblogs.com/manhua/上的作品创作. Lab - Inte ...

  10. Perl图书的一些体会

    近期,由于项目须要.又又一次将Perl学习起来. Perl老实说.让我又爱又恨. 爱它.是由于自己写代码的确非常爽. 是代码最少.速度最快的语言. 恨是由于看别人的代码实在太累了. 但,整体体会,在文 ...