传送门

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. Kali部署openvas初探与实践

    openvas安装 1.我用的清华大学的源,所以我把/etc/apt/source.list中下入如下源地址 #清华大学deb http://mirrors.tuna.tsinghua.edu.cn/ ...

  2. How `new’ operator works ?

    这是2013年写的一篇旧文,放在gegahost.net上面 http://raison.gegahost.net/?p=15 February 15, 2013 How `new’ operator ...

  3. DLL入门浅析【转】

     1.建立DLL动态库 动态链接库(DLL)是从C语言函数库和Pascal库单元的概念发展而来的.所有的C语言标准库函数都存放在某一函数库中.在链接应用程序的过程中,链接器从库文件中拷贝程序调用的函数 ...

  4. Photoshop 注册破解

    本机测试环境为Photoshop cs4 破解方式一: 打开C:\windows\system32\drivers\etc\"找到 hosts 文件, 右键点击--打开方式---记事本,然后 ...

  5. Graveyard LA3708

    白书第一章例题4 思维. 先固定一点不动,假设最后一共N个点,那么编号为0,1,...N-1, 0不动,原来的n个点分别占据i/n*N的位置(记为pos),移动到pos四舍五入的位置即可. 证明一:有 ...

  6. 第1节 flume:9、flume的多个agent串联(级联)

    3.两个agent级联 需求分析: 第一个agent负责收集文件当中的数据,通过网络发送到第二个agent当中去,第二个agent负责接收第一个agent发送的数据,并将数据保存到hdfs上面去 第一 ...

  7. 连接mysql 2003 Can't connect to Mysql on 'xxx'(10061)

    备份 cp /etc/mysql/my.cnf /etc/mysql/my.cnf.bak 修改 vim /etc/mysql/my.cnf 在[mysqld]下修改为bind-address=0.0 ...

  8. SQL比较两表字段和字段类型

    一.问题 业务需要把TB_Delete_KYSubProject表数据恢复到TB_KYSubProject,但提示错误,错误原因是两表字段类型存在不一致 insert into [TB_KYSubPr ...

  9. vue-cli中添加使用less

    在vue-cli中构建的项目是可以使用less的,但是查看package.json可以发现,并没有less相关的插件,所以我们需要自行安装. 第一步:安装 npm install less less- ...

  10. vue2.0中transition组件的用法

    作用:实现元素进入/离开的过渡效果. 首先,让我们举个栗子: <!DOCTYPE html> <html lang="en"> <head> & ...