传送门

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. 微信小程序 逻辑层

    1. 注册程序小程序APP在小程序的根目录下有一个app.js文件.有App(Object),App() 函数用来注册一个小程序.接受一个 Object 参数,其内便是小程序的生命周期.App() 必 ...

  2. Backbone.js之Todo源码浅析

    相信每个接触了解过backbone的人都知道todo,网上的关于它的分析教程也都分析乱了.但是,知识只有自己学习领悟才是自己的,话不多说,正文开始. 在分析todo的源码之前,首先我们要知道todo具 ...

  3. JSP报错The value for the useBean class attribute *** is invalid.

    环境:IDEA+Tomcat9+JDK1.8 在前期学习时,环境一直能够"正常"使用,实际上环境并没有完全搭建成功. 推荐: https://blog.csdn.net/lw_po ...

  4. ios 从相册视频中获取视频截图

    //给image添加个分类 +(UIImage *)getImage:(NSURL: *)videoURL { AVURLAsset *asset = [[AVURLAsset alloc] init ...

  5. 原创 齐天大圣老司机亲传rescue恢复磁盘分区

    老葵花哥哥课堂开课了本文档秉承爱看不看的原则 一不要钱 二服务大众的高尚情操咱们今天讲一讲rescue恢复磁盘分区 首先咱们搭建环境搞起来 (parted) mkpart #创建分区 Partitio ...

  6. Android(java)学习笔记174:服务(service)之混合方式开启服务

    1. 前面我们已经讲过可以使用两种方式开启服务 startService----stopService:        oncreate() ---> onstartCommand() ---& ...

  7. python struct.pack方法报错argument for 's' must be a bytes object 解决

    参考 https://blog.csdn.net/weixin_38383877/article/details/81100192 在python3下使用struct模块代码 fileHead = s ...

  8. HTML5新特性之History

    几年前,Ajax的兴起给互联网带来了新的生机,同时也使用户体验有了质的飞跃,用户无需刷新页面即可获取新的数据,而页面也以一种更具有交互性的形式为用户展现视图,可以说这种变化对互联网发展的贡献是史无前例 ...

  9. rfcn讲解博客

    http://www.cnblogs.com/lillylin/p/6277094.html ROI pooling操作的输入(对于C+1个类)是k^2*(C+1)*W' *H'(W'和H'是ROI的 ...

  10. 2018美赛准备之路——Matlab基础——基本运算符号表示

    π pi ln(x) log(x)   lg(x) log10(x) log2(x) log2(x) 根号 sqrt(x) x的y次方 x^y e的y次方 exp(y)