博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4045 Machine scheduling (第二类斯特林数+DP)
阅读量:5326 次
发布时间:2019-06-14

本文共 2513 字,大约阅读时间需要 8 分钟。

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. 

InputInput end with EOF. 

Input will be four integers n,r,k,m.We assume that they are all between 1 and 1000. 
OutputOutput 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.

 

题意,现在有1到n,n个数,从中选出r个数,要求选出的数的差至少为k,最后把选出的数放入不大于m个没有差异的盒子里面,问有多少种方案?取模1E9+7

分析:

需要进行两步操作,第一步是要选出r个数,求出共有多少种方案

第二步是在已经有了r个数,那么这r个数的具体值就不重要了,只需求把这r个数放入盒子里的方案数。

最后将两步的结果相乘

对于第一步操作:可以用dp[i][j]表示 数i是第j个数的方案数量

dp[i][j]=(dp[i][j]+dp[z][j-1])%MOD (z表示从1到i-k的数)

但是这样需要三重循环,所需时间超过数据范围

而这里实际上只与前(i-k)个的和有关,所以要用滚动数组的方式进行预处理

第二步:如果是刚好放入m个盒子,就是第二类斯特林数。但这里是放入不大于m个盒子,所以看做刚好放入(1到m)个盒子的第二类斯特林数求和

代码如下:

#include 
#include
#include
#include
#include
#include
using namespace std;typedef long long LL;LL stl[1100][1100];LL sumstl[1100][1100];LL dp[1100][1100];LL d[1100];LL d2[1100];const int MOD=1e9+7;void init(){ for(int i=1;i<=1000;i++) stl[i][i]=1; for(int i=1;i<=1000;i++) for(int j=1;j
=0) dp[i][j]=(dp[i][j]+d[i-k])%MOD; d2[i]=(d2[i-1]+dp[i][j])%MOD; } for(int z=1;z<=n;z++) d[z]=d2[z]; } for(int i=1;i<=n;i++) sum=(sum+dp[i][r])%MOD; // cout<
<

 

转载于:https://www.cnblogs.com/a249189046/p/8411106.html

你可能感兴趣的文章
PHP zip压缩文件及解压
查看>>
SOAP web service用AFNetWorking实现请求
查看>>
Java变量类型,实例变量 与局部变量 静态变量
查看>>
mysql操作命令梳理(4)-中文乱码问题
查看>>
Python环境搭建(安装、验证与卸载)
查看>>
一个.NET通用JSON解析/构建类的实现(c#)
查看>>
Windows Phone开发(5):室内装修 转:http://blog.csdn.net/tcjiaan/article/details/7269014
查看>>
详谈js面向对象 javascript oop,持续更新
查看>>
关于这次软件以及pda终端的培训
查看>>
jQuery上传插件Uploadify 3.2在.NET下的详细例子
查看>>
如何辨别一个程序员的水平高低?是靠发量吗?
查看>>
新手村之循环!循环!循环!
查看>>
ASP.NET中Request.ApplicationPath、Request.FilePath、Request.Path、.Request.MapPath
查看>>
正则表达式的用法
查看>>
线程安全问题
查看>>
集合的内置方法
查看>>
IOS Layer的使用
查看>>
Android中使用Handler造成内存泄露的分析和解决
查看>>
SSM集成activiti6.0错误集锦(一)
查看>>
个人作业
查看>>