当前位置:网站首页>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;
}
边栏推荐
- typeScript - Partially apply a function
- 00、数组及字符串常用的 API(详细剖析)
- .net(C#)获取两个日期间隔的年月日
- 标识符、关键字、常量 和变量(C语言)
- 进程间通信和线程间通信
- 2022牛客多校第三场 J题 Journey
- The master teaches you the 3D real-time character production process, the game modeling process sharing
- 【云原生--Kubernetes】Pod控制器
- leetcode: 266. All Palindromic Permutations
- gorm的Raw与scan
猜你喜欢
随机推荐
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
2022杭电多校第一场 1004 Ball
找不到DiscoveryClient类型的Bean
Cloud native - Kubernetes 】 【 scheduling constraints
Cython
动态上传jar包热部署
SQL association table update
[230]连接Redis后执行命令错误 MISCONF Redis is configured to save RDB snapshots
典型相关分析CCA计算过程
软件测试面试题:您以往所从事的软件测试工作中,是否使用了一些工具来进行软件缺陷(Bug)的管理?如果有,请结合该工具描述软件缺陷(Bug)跟踪管理的流程?
软件测试面试题:LoadRunner 分为哪三个模块?
IDEA 文件编码修改
MAUI Blazor 权限经验分享 (定位,使用相机)
【LeetCode】双指针题解汇总
【Unity编译器扩展之进度条】
LeetCode Hot 100
uinty lua 关于异步函数的终极思想
Flask框架 根据源码分析可扩展点
网站最终产品页使用单一入口还是多入口?
MongoDB permission verification is turned on and mongoose database configuration

![[Cloud Native--Kubernetes] Pod Controller](/img/e1/1a8cc82223f9a9be79ebbf1211e9a4.png)







