当前位置:网站首页>AcWing 300. Task arrangement
AcWing 300. Task arrangement
2022-07-02 16:31:00 【superhuanghai】
One 、 Sample explanation
Examples :
5 A mission , The start time of each task is 1
1 3 4 2 1
3 2 3 3 4
If we put the front 3 Treat a task as a batch , after 2 Treat a task as a batch .
that
The first batch of time points :1+3+4=8 It takes 8 Time , Plus the start time of a batch 1, It's a total of 9 Time
Time point of the second batch :2+1=3 It takes 3 Time , Plus the start time of a batch 1, Namely 4 Time , So the second time point is 9+4=13
Next, calculate the cost :
The total cost of the first batch is 3+2+3=8 The total cost is 8*9=72
The total cost of the second batch is 3+4=7 7*13=91
72+91=163
The optimal solution is 153, It seems that this division is not the optimal solution , good , Finished understanding the topic .
Two 、 Their thinking
Use The cost is calculated in advance Thought , Consider the subtasks of the current batch , Required startup time \(S\), The start time will be accumulated to the completion time of all tasks after this .
State definition
\(f[i]\) I'll go ahead \(i\) The minimum cost of dividing a task into several batches
Transfer equation
\(f[i]=min(f[j]+sumT[i]*(sumC[i]-sumC[j])+S*(sumC[N]-sumC[j])\)
Among them the first \(j+1\) to \(i\) Tasks are completed in the same batch
Algorithm design
Set double cycle , The time complexity is \(O(N^2)\)
loop 1: Set subbatch to \(i\) Tasks end
loop 2: Set subbatch to \(j\) Task is to start , among \(0<j<i-1\)
\(f[i]=min(f[i]\), Transfer equation calculation results )
3、 ... and 、 Implementation code
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5010;
int n;
LL s; // Waiting time
LL sc[N]; // Each task has a cost , use c[i] To express ,sc[i] It's the prefix and
LL st[N]; // Each task has its own execution time t[i], The prefix and are st[i]
LL f[N];
int main() {
// Optimize input
ios::sync_with_stdio(false);
cin >> n >> s;
for (int i = 1; i <= n; i++) {
LL t, c;
cin >> t >> c;
st[i] = t + st[i - 1];
sc[i] = c + sc[i - 1];
}
// initialization
memset(f, 0x3f, sizeof f);
f[0] = 0;
//n^2 The time complexity of the
for (int i = 1; i <= n; i++)
for (int j = 0; j < i; j++)
f[i] = min(f[i], f[j] + st[i] * (sc[i] - sc[j]) + s * (sc[n] - sc[j]));
// Output
printf("%lld\n", f[n]);
return 0;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
边栏推荐
- Add user-defined formula (time sharing t+0) to mobile app access as an example
- Multi data source configuration code
- AWS云主机扩容
- Bean configuration override in boot
- 头条 | 亚控科技产品入选中纺联《纺织服装行业数字化转型解决方案重点推广名录》
- ROW_ NUMBER()、RANK()、DENSE_ Rank difference
- Sqlserver queries which indexes are underutilized
- Everyone Xinfu builds: a one-stop intelligent business credit service platform
- What is the difference between self attention mechanism and fully connected graph convolution network (GCN)?
- Vscade set multi line display of tab
猜你喜欢

Practice of constructing ten billion relationship knowledge map based on Nebula graph

Dimension table and fact table in data warehouse

Solve * * warning * *: your ApplicationContext is unlikely to start due to a @componentscan of the defau

通过两级网关设计来路由服务网格流量

dried food! Understand the structural vulnerability of graph convolution networks

请问怎么在oracle视图中使用stustr函数

Effectively use keywords to increase Amazon sales

去除router-link中的下划线

Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus

Huawei ECS installs mysqlb for mysqld service failed because the control process exited with error code. See “sys
随机推荐
原神2.6服务端下载以及搭建安装教程
PCL point cloud image transformation
By asp Net core downloads files according to the path exception
曆史上的今天:支付寶推出條碼支付;分時系統之父誕生;世界上第一支電視廣告...
Practice of traffic recording and playback in vivo
Kubernetes family container housekeeper pod online Q & A?
ROW_ NUMBER()、RANK()、DENSE_ Rank difference
Practice of constructing ten billion relationship knowledge map based on Nebula graph
Today in history: Alipay launched barcode payment; The father of time-sharing system was born; The first TV advertisement in the world
分析超700万个研发需求发现,这8门编程语言才是行业最需要的!
Dimension table and fact table in data warehouse
Introduction to database system Chapter 1 short answer questions - how was the final exam?
2022 the latest and most detailed will successfully set the background image in vscade and solve unsupported problems at the same time
After the win10 system is upgraded for a period of time, the memory occupation is too high
mysql 计算经纬度范围内的数据
触发器:Mysql实现一张表添加或删除一条数据,另一张表同时添加
Recommended practice sharing of Zhilian recruitment based on Nebula graph
Effectively use keywords to increase Amazon sales
The difference and usage of calloc, malloc and realloc functions
Library management system (Shandong Agricultural University Curriculum Design)