传送门

Machine scheduling

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

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:  4043 4047 4050 4048 4042 
 
题意:n个机器,每天选出r台,将其分成不超过m组,要求选出的机器之间编号之差>=k,每天的选择不能与之前相同,问最多能有多少天。
题解:
将r台机器分成不超过m组,可以用斯特林数进行预处理。下面就是求选出r台机器的方案数了。
然后dp[i][j]表示,选择编号i的机器,在[i,n]的区间里面需要选择j台机器的方案数。
sum[i][j]表示在[i,n]的区间里面需要选择j台机器的方案数。
那么转移方程为:
dp[i][j]=sum[i+k][j-1];
sum[i][j]=sum[i+1][j]+dp[i][j];
13083183 2015-03-10 19:16:25 Accepted 4045 358MS 25380K 1461 B G++ czy
 #include <cstdio>
#include <cstring>
#include <stack>
#include <algorithm> #define ll long long
int const N = ;
ll const mod = ; using namespace std; ll stl[N][N];
ll sumstl;
ll n,r,k,m;
ll dp[N][N];
ll sum[N][N];
ll ans; void ini1()
{
memset(stl,,sizeof(stl));
ll i;
for(i=;i<=;i++){
stl[i][i]=;
}
stl[][]=;
ll p,j;
for(p=;p<=;p++){
for(j=;j<=p;j++){
stl[p][j]= (j*stl[p-][j]+stl[p-][j-])%mod;
}
} //for(p=1;p<=10;p++){
// for(j=1;j<=p;j++) printf(" p=%I64d j=%I64d stl=%I64d\n",p,j,stl[p][j]);
// }
} void ini()
{
ll i;
sumstl=;
for(i=;i<=m;i++){
sumstl=(sumstl+stl[r][i])%mod;
}
memset(dp,,sizeof(dp));
memset(sum,,sizeof(sum));
ans=;
// printf(" sumstl=%I64d\n",sumstl);
} void solve()
{
int i,j;
for(i=n;i>=;i--){
dp[i][]=;
sum[i][]=(sum[i+][]+dp[i][])%mod;
}
for(j=;j<=r;j++){
for(i=n-k;i>=;i--){
dp[i][j]=sum[i+k][j-];
sum[i][j]=(sum[i+][j]+dp[i][j])%mod;
}
}
ans=(sum[][r]*sumstl)%mod;
} void out()
{
printf("%I64d\n",ans);
} int main()
{
//freopen("data.in","r",stdin);
ini1();
while(scanf("%I64d%I64d%I64d%I64d",&n,&r,&k,&m)!=EOF)
{
ini();
solve();
out();
}
}

hdu 4045 Machine scheduling [ dp + 斯特林数]的更多相关文章

  1. HDU 4045 Machine scheduling (组合数学-斯特林数,组合数学-排列组合)

    Machine scheduling Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

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

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

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

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

  4. dp 斯特林数 HDU2512一卡通大冒险

    这道题其实就是斯特林数,找不同的集合,一共有多少中组法,递推式就是dp[n][k] = dp[n - 1][k - 1] + k * dp[n - 1][k]; 这个式子可以这么解释,dp[n][k] ...

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

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

  6. 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 ...

  7. HDU 1176 免费馅饼 DP类似数塔题

    解题报告: 小明走在一条小路上,这条小路的长度是10米,从左到右依次是0到10一共十个点,现在天上会掉馅饼,给出馅饼掉落的坐标和时间,一开始小明的位置是在坐标为5的位置, 他每秒钟只能移动一米的距离, ...

  8. [Luogu5320][BJOI2019]堪破神机(DP+斯特林数)

    https://www.cnblogs.com/cjyyb/p/10747543.html 特征方程+斯特林反演化简式子,要注意在模998244353意义下5没有二次剩余,所以每个数都要用$a+b\s ...

  9. BZOJ2159 Crash的文明世界(树形dp+斯特林数)

    根据组合意义,有nk=ΣC(n,i)*i!*S(k,i) (i=0~k),即将k个有标号球放进n个有标号盒子的方案数=在n个盒子中选i个将k个有标号球放入并且每个盒子至少有一个球. 回到本题,可以令f ...

随机推荐

  1. JVM内存区域参数配置

    转自:https://www.jianshu.com/p/5946c0a414b5 需要提前了解的知识点: JVM内存模型 JVM垃圾回收算法 下图是JVM内存区域划分的逻辑图   JVM内存区域逻辑 ...

  2. 读取Chrome书签文件

    使用C#读取Chrome浏览器的本地书签文件,当前文件在C盘下用户文件夹\AppData\Local\Google\Chrome\User Data\Default\下的Bookmarks 打开这个文 ...

  3. qt5.8+vs2015使用Qt5WebEngine搭建环境

    转载请注明出处:http://www.cnblogs.com/dachen408/p/7575094.html 1.项目属性,C/C++,所有选项,附加包含目录新增. $(QTDIR)\include ...

  4. 初探ABP--记一些常见的开发问题

    1.Update-Database : 无法将“Update-Database”项识别为 cmdlet.函数.脚本文件或可运行程序的名称.请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次. ...

  5. gulp自动化构建工具使用

    gulpfile.js: var gulp = require("gulp"); var imagemin = require("gulp-imagemin") ...

  6. javaee 第八周作业

    hashcode()和equals()的作用.区别.联系 先来试想一个场景,如果你想查找一个集合中是否包含某个对象,那么程序应该怎么写呢?通常的做法是逐一取出每个元素与要查找的对象一一比较,当发现两者 ...

  7. (转)Spring的三种实例化Bean的方式

    http://blog.csdn.net/yerenyuan_pku/article/details/52832793 Spring提供了三种实例化Bean的方式. 使用类构造器实例化. <be ...

  8. 关于JDBC访问存储过程的问题

    最近开发一个应用,需要调用一个入参为List的存储过程. 存储过程为: proc_test(p1 OUT Number, p2 IN Number, p3 IN TAB_CUSTOMER); 这个Li ...

  9. jquery.placeholder.min.js让吃屎的IE浏览器支持placeholder去吧

    描述:现在都是HTML5时代了,所有的浏览器都支持placeholder,唯独IE不支持.现在我们有了这款插件,IE下终于可以支持了!  图片展示:   兼容浏览器:IE6+/Firefox/Goog ...

  10. JSP页面通过c:forEach标签循环遍历List集合

    c:forEach>标签有如下属性: 属性 描述 是否必要 默认值items 要被循环的信息 否 无begin 开始的元素(0=第一个元素,1=第二个元素) 否 0end 最后一个元素(0=第一 ...