[关闭]
@2368860385 2020-11-07T03:06:10.000000Z 字数 1228 阅读 181

day12

正睿停课


T1

T2

#109. 【17 提高 7】当那一天来临

首先考虑确定了工作顺序如何计算时间。

模拟?

表示到了第i个物品,已经被前j个机器加工完了。
表示第i个物品如果要被第j个机器加工,必须等这个物品被前一个机器加工完,而且也要等这个机器加工完它前面的物品,取一个最大值,然后发现这个dp就是在3*n的矩阵上求一个从(0,0)到(3,n)的最长路。

然后考虑如何确定顺序。
题目中保证了第二行一定小于第三行,那么最长路一定是经过第二行一个点。
考虑两列,是否交换。
两列初始时是这样的,交换完也只会影响两条路径。
经过这两列的最大的路径:两个蓝色+max(红,绿)
所以分别计算交换前和交换后的最大路径,如果交换后小了,就交换。

  1. #include<cstdio>
  2. #include<algorithm>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<iostream>
  6. #include<cctype>
  7. #include<set>
  8. #include<vector>
  9. #include<queue>
  10. #include<map>
  11. #define fi(s) freopen(s,"r",stdin);
  12. #define fo(s) freopen(s,"w",stdout);
  13. using namespace std;
  14. typedef long long LL;
  15. inline int read() {
  16. int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
  17. for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
  18. }
  19. const int N = 100005;
  20. struct Node{
  21. int a, b, c;
  22. }A[N];
  23. LL sa[N], sc[N];
  24. bool operator < (const Node &x, const Node &y) {
  25. return x.a + y.c + max(x.b + x.c, y.a + y.b) < y.a + x.c + max(y.b + y.c, x.a + x.b);
  26. }
  27. int main() {
  28. int n = read();
  29. for (int i = 1; i <= n; ++i) {
  30. A[i].a = read(), A[i].b = read(), A[i].c = read();
  31. }
  32. sort(A + 1, A + n + 1);
  33. for (int i = 1; i <= n; ++i) sa[i] += sa[i - 1] + A[i].a;
  34. for (int i = n; i >= 1; --i) sc[i] += sc[i + 1] + A[i].c;
  35. LL ans = 0;
  36. for (int i = 1; i <= n; ++i)
  37. ans = max(ans, sa[i] + A[i].b + sc[i]);
  38. cout << ans;
  39. return 0;
  40. }
  41. /*
  42. 3
  43. 5 3 4
  44. 3 2 9
  45. 3 4 8
  46. */
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注