当前位置:网站首页>1723. minimum time to complete all work
1723. minimum time to complete all work
2022-06-12 17:08:00 【anieoo】
Original link :1723. The shortest time to complete all the work
solution:
dfs + to flash back + prune

① The end condition : Task assignment completed ,maxt Save the maximum working hours of all workers , Reuse maxt And the previous maximum working hours res Compare , to update res.
② Allocate time , Depth-first search , Assign all tasks to the first person first , Go back and assign to the next person .
③ Pruning conditions 1: If the currently assigned worker hours are greater than the maximum worker hours at the end of the previous assignment , Pruning
④ Pruning conditions 2: If you go back , Working hours of workers workers[i] == 0, Pruning , Because the worker's later working hours are all 0, It makes no sense .
class Solution {
public:
int res = INT_MAX;
int minimumTimeRequired(vector<int>& jobs, int k) {
vector<int> workers (k, 0); // Define the working hours of each worker
dfs(workers, jobs, 0);
return res;
}
void dfs(vector<int> &workers,vector<int>& jobs,int index) {
if(index == jobs.size()) { // If all tasks are assigned , Updated once res
int maxt = -1;
for(int i = 0;i < workers.size();i++) { // Task assignment completed , Save maximum working time
maxt = max(maxt, workers[i]);
}
res = min(res, maxt); // Update the minimum maximum working time
return;
}
for(int i = 0;i < workers.size();i++) { // Allocate time
if(workers[i] + jobs[index] >= res) { // If this assignment is greater than the previous minimum maximum working time , prune
continue;
}
workers[i] += jobs[index];
dfs(workers,jobs,index + 1);
workers[i] -= jobs[index]; // to flash back
if(workers[i] == 0) break; // prune
}
}
};
边栏推荐
- 男神女神投票源码 v5.5.21 投票源码
- 博士申请 | 新加坡国立大学Xinchao Wang老师招收图神经网络方向博士/博后
- Microsoft Office MSDT Code Execution Vulnerability (cve-2022-30190) vulnerability recurrence
- Qt开发高级进阶:初探qt + opengl
- R语言使用pdf函数将可视化图像结果保存到pdf文件中、使用pdf函数打开图像设备、使用dev.off函数关闭图像设备、自定义width参数和height参数指定图像的宽度和高度
- Selenium element positioning
- 2080虚拟机登录命令
- Dongfeng Yueda Kia, Tencent advertising and hero League mobile game professional league cooperate to build a new E-sports ecology
- Doctor application | National University of Singapore, Xinchao Wang, teacher recruitment, doctor / postdoctoral candidate in the direction of graph neural network
- Structural requirement analysis of software engineering student information management system
猜你喜欢

Record the use of yolov5 to detect rotating targets

Microsoft Office MSDT代码执行漏洞(CVE-2022-30190)漏洞复现

RMI, JNDI, LDAP introduction +log4j vulnerability analysis

Unit sshd.service could not be found

SwinTransformer网络架构

Demande de doctorat | xinchao Wang, Université nationale de Singapour

Detailed explanation of shardingjdbc database and table

使用GCC的PGO(Profile-guided Optimization)优化整个系统

2080虚拟机登录命令

MySQL transaction introduction and transaction isolation level
随机推荐
Some minor problems and solutions encountered when using ubantu
Cloud development kunkun chicken music box wechat applet source code
(六)控制语句if/else switch
Pat class a 1142 largest regiment
Crazy temporary products: super low price, big scuffle and new hope
(八)goto关键字
Difference between big end mode and small end mode
邱盛昌:OPPO商业化数据体系建设实战
Loading shellcode in C and go languages
5-5 configuring MySQL replication log point based replication
uabntu的sudo
Idea how to set the guide package without * sign
JVM内存模型与本地内存
Gerrit+2触发Jenkins任务
并发三色标记法
Nebula's practice of intelligent risk control in akulaku: training and deployment of graph model
Recommend 6 open source projects of yyds
R language uses the sum function of epidisplay package to calculate the descriptive statistical summary information of the specified variables in dataframe under different grouped variables and visual
每天5分钟玩转Kubernetes | 汇总
PAT甲级 1139 第一次接触