当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

STC89C52RC的P4口的应用问题

三、实战---爬取百度指定词条所对应的结果页面(一个简单的页面采集器)

性能测试如何准备测试数据

Implementation principle of golang coroutine

【LeetCode】图解 904. 水果成篮

KT6368A Bluetooth certification problem_FCC and BQB_CE_KC certification or other instructions

英特尔WiFi 7产品将于2024年亮相 最高速度可达5.8Gbps

《WEB安全渗透测试》(28)Burp Collaborator-dnslog外带技术

找不到DiscoveryClient类型的Bean

oracle创建用户以后的权限问题
随机推荐
leetcode: 266. All Palindromic Permutations
The applicable scenarios and common product types of the KT148A electronic voice chip ic solution
leetcode经典例题——单词拆分
"Relish Podcast" #397 The factory manager is here: How to use technology to empower the law?
翁恺C语言程序设计网课笔记合集
[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots
仿网易云音乐小程序-uniapp
uinty lua 关于异步函数的终极思想
2022杭电多校 第三场 B题 Boss Rush
LeetCode Hot 100
Handwritten Distributed Configuration Center (1)
克服项目管理中恐惧心理
典型相关分析CCA计算过程
Statistical words (DAY 101) Huazhong University of Science and Technology postgraduate examination questions
2 用D435i运行VINS-fusion
软件测试面试题:一套完整的测试应该由哪些阶段组成?
Raw and scan of gorm
What is next-generation modeling (with learning materials)
typeScript - Partially apply a function
软件测试面试题:软件验收测试的合格通过准则?