当前位置:网站首页>More than 2022 cattle school training topic Link with the second L Level Editor I
More than 2022 cattle school training topic Link with the second L Level Editor I
2022-08-05 00:22:00 【雨肯定】
题目链接
题目大意
大概意思就是,给了我们 n n n个世界,每个世界有 m m m个点,There are several directed edges in each world,will connect some points.我们需要从1号点出发,最终走到 m m m号点,Each time you can choose to choose a directed edge at the current point of the current world to go to another point,Or teleport directly to the next world,The question asks us the minimum need to choose how many worlds can be achieved from1走到 m m m.
题解
考虑DP,设 f i , j f_{i, j} fi,j表示在第 i i iworld to go j j j点,Which world to start from at the latest,Because of the problem card memory,We need to optimize it with rolling arrays.And also need to pay attention to some details of the state transition process,If the current directed edge is from1号点出发的,We need to write the current latest world 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;
}
边栏推荐
- 《WEB安全渗透测试》(28)Burp Collaborator-dnslog外带技术
- redis可视化管理软件Redis Desktop Manager2022
- How to automatically push my new articles to my fans (very simple, can't learn to hit me)
- typeScript - Partially apply a function
- 子连接中的参数传递
- gorm联表查询-实战
- leetcode: 266. All Palindromic Permutations
- 软件测试面试题:关于自动化测试工具?
- 软件测试面试题:软件都有多少种分类?
- 【Unity编译器扩展之进度条】
猜你喜欢
随机推荐
IDEA file encoding modification
翁恺C语言程序设计网课笔记合集
Senior game modelers tell newbies, what are the necessary software for game scene modelers?
oracle创建用户以后的权限问题
10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻
典型相关分析CCA计算过程
oracle创建用户
gorm联表查询-实战
机器学习(公式推导与代码实现)--sklearn机器学习库
软件测试面试题:LoadRunner 分为哪三个模块?
倒计时1天!8月2日—4日与你聊聊开源与就业那些事!
2022杭电多校 第三场 B题 Boss Rush
【LeetCode】双指针题解汇总
Will domestic websites use Hong Kong servers be blocked?
【数据挖掘概论】数据挖掘的简单描述
2022牛客多校第三场 J题 Journey
统计单词(DAY 101)华中科技大学考研机试题
jenkins send mail system configuration
Couple Holding Hands [Greedy & Abstract]
软件测试面试题:您以往所从事的软件测试工作中,是否使用了一些工具来进行软件缺陷(Bug)的管理?如果有,请结合该工具描述软件缺陷(Bug)跟踪管理的流程?









