传送门

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. fsck和badlocks

    fsck可以检查好几种不同的文件系统,fsck只是一个中和程序而已,个别的文件系统检查程序都在/sbin中,可以使用ls -l /sbin/fsck* -A 按照/etc/fstab的内容,将所有的设 ...

  2. 时间插件-daterangepicker

    一款基于bootstrap的时间插件daterangepicker,顾名思义,主要用于时间区间选择,也可做单个时间选择 demo.1汉化版的一个时间选择案例 <!DOCTYPE html> ...

  3. Summary of 2016 International Trusted Computing and Cloud Security Summit

    1)      Welcome Remarks 2)      The advancement of Cloud Computing and Tursted Computing national st ...

  4. 设置QtreeWidget水平滚动条

    转载请注明出处:http://www.cnblogs.com/dachen408/p/7552603.html //设置treewidget水平滚动条 ui.treeWidget->header ...

  5. log4j 日志分级处理

    log4j 配置文件: log4j.rootLogger=debug,stdout,debug,info,errorlog4j.appender.stdout=org.apache.log4j.Con ...

  6. UVA 11922 Permutation Transformer (Splay树)

    题意: 给一个序列,是从1~n共n个的自然数,接下来又m个区间,对于每个区间[a,b],从第a个到第b个从序列中分离出来,翻转后接到尾部.输出最后的序列. 思路: 这次添加了Split和Merge两个 ...

  7. hdu 2192 MagicBuilding

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  8. 详解nginx.conf文件配置项(包括负载均衡)

    http://www.cnblogs.com/hsapphire/archive/2010/04/08/1707109.html #运行用户 user  nobody nobody; #启动进程 wo ...

  9. 在Oracle用SQL处理以 System.currentTimeMillis

    有時為了系統的需求會紀錄到毫秒(Millisecond),我們會接將得到的值寫入db,但是如果要用SQL 做時間範圍的搜尋,有以下做法( systemdate欄位存放System.currentTim ...

  10. iview table icon dorpdown html页面级别vue组件 #vuez#

    iview table icon dorpdown html页面级别vue组件 <!DOCTYPE html> <html> <head> <meta cha ...