HDU/HDOJ 4045 BUPT 216 Machine scheduling 2011ACM北京网络赛 F题

本文探讨了一个具体的机器调度问题,旨在解决百度工程师如何高效地分配机器处理数据的任务,同时避免重复的分配方案导致的初始化问题。文章详细介绍了问题背景、输入输出格式及样例,并给出了具体的算法实现思路和代码。
摘要由CSDN通过智能技术生成
Machine scheduling
Accept:8Submit:35
Time Limit:2000MSMemory Limit:65536KB
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.

这个题主要是推公式。

要分为两个部分。第一部分为从n台机器里面选出r台,第二部分为把r个机器放进m个组

这两个部分的答案乘积就是最后的答案

第二部分很好算,就是一个第二类的斯特林数求和

第一部分比较麻烦,我在纸上画了好久才发现规律

第一部分的递推式:

s[i][j]=s[i-1][j]+s[i][j-1]

第二部分的递推式(斯特林数求和)

s[n][m]=m*s[n-1][m]+s[n-1][m-1]

ans=s[n][1]+s[n][2]+...+s[n][m]

我的代码:

BUPT上面交的话,记得把__int64改为long long,%I64d改为%lld

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; typedef __int64 ll; ll sum1[1005][1005]; ll sum2[1005][1005]; ll mod=1000000007; void init() { ll i,j; for(i=1;i<=1000;i++) { sum1[i][1]=1; sum1[1][i]=i; } for(i=2;i<=1000;i++) for(j=2;j<=1000;j++) sum1[i][j]=(sum1[i-1][j]+sum1[i][j-1])%mod; for(i=1;i<=1000;i++) { sum2[i][1]=1; sum2[i][i]=1; } for(i=2;i<=1000;i++) for(j=2;j<=i;j++) sum2[i][j]=(j*sum2[i-1][j]+sum2[i-1][j-1])%mod; } ll cal(ll n,ll m) { ll i,sum=0; for(i=1;i<=m;i++) sum=(sum+sum2[n][i])%mod; return sum; } int main() { ll n,r,k,m,tmp,ans; init(); while(scanf("%I64d%I64d%I64d%I64d",&n,&r,&k,&m)!=EOF) { tmp=k*(r-1)+1; if(tmp>n) { printf("0\n"); continue; } tmp=n-k*(r-1); ans=cal(r,m)*sum1[r][tmp]%mod; printf("%I64d\n",ans); } return 0; }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值