I. Tetris

题意:
设定俄罗斯方块的界面大小是 1e9∗k1e9*k1e9∗k的, k<=10k<=10k<=10,有 n<=5000n<=5000n<=5000 个 高度为1的长方条,每个能覆盖 l[i],r[i]l[i],r[i]l[i],r[i] 的区间,每个长方条 有个价值 w[i]w[i]w[i],问不超出界面,最多能得到多少价值。

思路:
考虑网络流,将每个 lll 和 rrr 离线下来 当作点,每个点按照顺序,向下一个点,连接一条 容量为 kkk,费用为 0 的边。然后选择一个方块放下,即选择一条边 跨过 l到rl到rl到r,即从 lll 向 r+1r+1r+1 连接一条容量为1,费用为 −w[i]-w[i]−w[i] 的边,求最小费用即可。

不怕死用迪杰斯特拉 疯狂 T101T101T101,可能就是负权使得 同一个点,进入队列的次数太大了,用 SPFASPFASPFA就过了,TATTATTAT

代码:

#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long longinline int qread(){int s=0,w=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')w=-1;for (;ch>='0'&&ch<='9';ch=getchar())s=(s<<1)+(s<<3)+(ch^48);return (w==-1?-s:s);}int n,m;typedef pair<ll,int> P;
const int maxn=1e4+50;
const int INF=1e14+7;
bool vis[maxn];
ll cst[maxn],flow[maxn];
int pre[maxn],last[maxn];struct Edge{int to,next;ll flow,cst;
}edge[maxn*3];
int head[maxn],num_edge=0;
queue<int>q;
void adeg(int from,int to,ll flow,ll cst)
{edge[++num_edge].next=head[from];edge[num_edge].to=to;edge[num_edge].flow=flow;edge[num_edge].cst=cst;head[from]=num_edge;
}
void add(int from,int to,ll flow,ll cst){adeg(from,to,flow,cst);adeg(to,from,0,-cst);
}
bool spfa(int s,int t)
{memset(cst,0x7f,sizeof(cst));memset(flow,0x7f,sizeof(flow));memset(vis,0,sizeof(vis));q.push(s);vis[s]=1;cst[s]=0;pre[t]=-1;while(!q.empty()){int now=q.front();q.pop();vis[now]=0;for (int i=head[now]; i!=-1; i=edge[i].next){if (edge[i].flow>0 && cst[edge[i].to]>cst[now]+edge[i].cst){cst[edge[i].to]=cst[now]+edge[i].cst;pre[edge[i].to]=now;last[edge[i].to]=i;flow[edge[i].to]=min(flow[now],edge[i].flow);if (!vis[edge[i].to]){vis[edge[i].to]=1;q.push(edge[i].to);}}}}return pre[t]!=-1;
}void MCMF(int S,int T,ll &MF,ll &MC)
{while (spfa(S,T)){int now=T;MF+=flow[T];MC+=flow[T]*cst[T];while (now!=S){edge[last[now]].flow-=flow[T];edge[last[now]^1].flow+=flow[T];now=pre[now];}}
}void init(){memset(head,-1,sizeof(head));num_edge=-1;//初始化
}
struct node{int a,b,w;
}z[5005];
int tot=0;
int ss[10005];
unordered_map<int,int>mpp;
int main(){init();n=qread(),m=qread();mpp.clear();for(int i=1;i<=n;i++){int a=qread(),b=qread(),c=qread();b++;z[i].w=c;z[i].a=a;z[i].b=b;ss[2*i-1]=a;ss[2*i]=b;}sort(ss+1,ss+1+2*n);for(int i=1;i<=2*n;i++){if(!mpp.count(ss[i]))mpp[ss[i]]=++tot;}int s=tot+1;int t=s+1;add(s,1,m,0);for(int i=2;i<=tot;i++){add(i-1,i,m,0);}add(tot,t,m,0);for(int i=1;i<=n;i++){int l=mpp[z[i].a];int r=mpp[z[i].b];add(l,r,1,-z[i].w);}ll F=0,C=0;MCMF(s,t,F,C); printf("%lld\n",-C);return 0;
}

2021-2022 ICPC, NERC, Southern and Volga Russian Regional Contest I. Tetris相关推荐

  1. 2021-2022 ICPC, NERC, Southern and Volga Russian Regional Contest Smash the Trash(二分)

    2021-2022 ICPC, NERC, Southern and Volga Russian Regional Contest Smash the Trash(二分) 链接 题意: 思路:二分答案 ...

  2. 2021-2022 ICPC, NERC, Southern and Volga Russian Regional Contest X-Magic Pair(gcd)

    2021-2022 ICPC, NERC, Southern and Volga Russian Regional Contest X-Magic Pair(gcd) 链接 题意:给出a,b,有两种选 ...

  3. 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest 部分题解ABFHJLN

    2020-10-10为了准备CCPC,师兄下午拉了场ICPC练习让我们模拟,负责读题的菜鸡晚上回来重新做了模拟场上有思路的题QAQ 文章目录 A - Berstagram B - The Feast ...

  4. 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest K. The Robot

    翻译: 有一个机器人在一个没有尽头的方格场上.最初,机器人位于坐标为(0,0)的单元中.他将执行由一串大写拉丁字母"L"."R"."D".& ...

  5. 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest

    A.Berstagram 题意:起始数列是1,2,3,--,n,给你m个操作x,表示将数字x和前一个位置的数交换,如果已经在第一个则不做操作,求每个数能到达的位置的最大和最小值: 分析:扫一遍模拟,更 ...

  6. 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest B. The Feast and the Bus (经典贪心)

    题目链接 思路:先把k个团队的人数从大到小排序,我们发现s最小是num[1],那么s最大是num[1]+num[2]?可是我们这样想的话容易被毒瘤数据tle,所以还得优化一下,我们可以想我们最优的方案 ...

  7. 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest B. Bakery

    题目链接 Monocarp would like to open a bakery in his local area. But, at first, he should figure out whe ...

  8. 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest A. LaIS

    题目链接 Let's call a sequence b1,b2,b3-,bk−1,bkb_1, b_2, b_3 \dots, b_{k - 1}, b_kb1​,b2​,b3​-,bk−1​,bk ...

  9. 2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest J. The Parade(二分)

    题目链接 题意:给定身高为1-n的士兵数量,现在要求士兵分成k排,要求每一排士兵身高差不能超过1,求最多有多少士兵可以拿出来排. 思路:又是一个裸的二分题,但是写check函数的时候确遇到了bug.. ...

最新文章

  1. java smtp 内嵌图片,SMTP 发送内嵌图片 邮件
  2. rsync+inotify-tools实现文件的实时同步
  3. pythondistinct教程_mongodb如何执行distinct
  4. 陕西小学三年级计算机下册教案,小学三三年级信息技术下册教学计划
  5. python_易忘的简单知识点总结
  6. OpenGL 加载模型Model
  7. Python3网络爬虫——(4)urllib.error异常处理
  8. Angular 2 JIT vs AOT
  9. Syntax error, parameterized types are only available if source level is 1.5 or greater
  10. 工业交换机是什么?矿用交换机采用的是工业级交换机吗?
  11. 苹果发布会日期再曝光 2019新iPhone发布会定在这一天?
  12. MooFest POJ - 1990
  13. 学习JavaScript数据结构与算法-----pdf 分享
  14. Google地球查看香港地形
  15. Delphi的命令行编译命令
  16. echarts无数据时显示无数据_无服务器数据库竞技,哪家云服务落伍了?
  17. python爬虫微信_python 微信爬虫
  18. 简单使用Easy Touch5摇杆控制物体移动
  19. sklearn神经网络/BP神经网络实现葡萄酒分类问题
  20. 小程序源码:uni-app云开发的网盘助手

热门文章

  1. 初中教师计算机培训方案,学校教师信息技术应用能力提升培训方案
  2. 玩转微信内SaaS直播间 “微赞”获IDG千万元A轮融资
  3. 2022-07-15 网工进阶(十九)BGP-状态机、对等体之间的交互原则、影响对等体关系建立的因素、对等体表、路由表、详细路由表、路由属性
  4. Oh My God!1个客服同时对接8个微信号,32000人!销售转化率提升3倍,复购率提高60%,7天留存率提升200%!...
  5. matlab如何将代码生成模型,为模型生成 C 代码
  6. 道cpu、道指令、道编程基本原理15
  7. 数据分析之预测模型项目模板
  8. 国外第三方分享,包括Facebook,twitter,Instagram
  9. android toast怎么改变位置,Android 更改 Toast 的默认位置方法
  10. 网络安全也要迈入AI时代?微软推出Security Copilot安全助手