当前位置:网站首页>2022牛客多校训练第二场 L题 Link with Level Editor I
2022牛客多校训练第二场 L题 Link with Level Editor I
2022-08-05 00:18:00 【Rain Sure】
题目链接
题目大意
大概意思就是,给了我们 n n n个世界,每个世界有 m m m个点,每个世界中存在若干条有向边,会将某些点连起来。我们需要从1号点出发,最终走到 m m m号点,每次可以选择在当前世界的当前点选择一条有向边出发走到另一个点,或者直接传送到下一个世界,题目问我们最小需要选择几个世界可以实现从1走到 m m m。
题解
考虑DP,设 f i , j f_{i, j} fi,j表示在第 i i i个世界走到 j j j点,最晚从哪个世界出发,由于题目卡内存了,我们需要使用滚动数组优化一下。并且还需要注意状态转移过程中的一些细节,假如当前的有向边是从1号点出发的,我们需要将当前最晚的世界写成 i i i。具体看代码
#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 2010, inf = 0x3f3f3f3f;
int f[2][maxn];
int n, m;
int main()
{
cin >> n >> m;
memset(f, -0x3f, sizeof f);
int res = inf;
for(int i = 1; i <= n; i ++){
int num; cin >> num;
f[(i - 1) & 1][1] = i; // 尤其需要注意
for(int j = 1; j <= m; j ++) f[i & 1][j] = f[(i - 1) & 1][j];
while(num --) {
int a, b; cin >> a >> b;
f[i & 1][b] = max(f[i & 1][b], f[(i - 1) & 1][a]);
if(b == m) res = min(res, i - f[i & 1][m] + 1);
}
}
if(res >= inf / 2) cout << -1 << endl;
else cout << res << endl;
}
边栏推荐
- E - Many Operations (按位考虑 + dp思想记录操作后的结果
- SV 类的虚方法 多态
- Essential knowledge for entry-level 3D game modelers
- 2022杭电多校第一场 1004 Ball
- 软件测试面试题:您如何看待软件过程改进?在您曾经工作过的企业中,是否有一些需要改进的东西呢?您期望的理想的测试人员的工作环境是怎样的?
- The master teaches you the 3D real-time character production process, the game modeling process sharing
- 2022杭电多校 第三场 B题 Boss Rush
- 机器学习(公式推导与代码实现)--sklearn机器学习库
- The applicable scenarios and common product types of the KT148A electronic voice chip ic solution
- tensor.nozero(), mask, [mask]
猜你喜欢
随机推荐
10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻
【LeetCode】矩阵模拟相关题目汇总
Brainstorm: Complete Backpack
Cython
【LeetCode】图解 904. 水果成篮
软件测试面试题:一套完整的测试应该由哪些阶段组成?
Huggingface入门篇 II (QA)
tiup status
【无标题】
[LeetCode] Summary of Matrix Simulation Related Topics
数据类型-整型(C语言)
oracle创建用户以后的权限问题
tiup uninstall
电子行业MES管理系统的主要功能与用途
TinyMCE禁用转义
克服项目管理中恐惧心理
MVCC是什么
【idea】idea配置sql格式化
QSunSync 七牛云文件同步工具,批量上传
Three tips for you to successfully get started with 3D modeling









