当前位置:网站首页>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;
}
边栏推荐
- 国内网站用香港服务器会被封吗?
- gorm联表查询-实战
- First, the basic concept of reptiles
- leetcode: 266. All Palindromic Permutations
- 软件测试面试题:软件验收测试的合格通过准则?
- 刘润直播预告 | 顶级高手,如何创造财富
- 软件测试面试题:做好测试计划的关键是什么?
- Couple Holding Hands [Greedy & Abstract]
- Statistical words (DAY 101) Huazhong University of Science and Technology postgraduate examination questions
- LeetCode Hot 100
猜你喜欢
翁恺C语言程序设计网课笔记合集
Implementation principle of golang coroutine
子连接中的参数传递
Mysql_14 存储引擎
怎样进行在不改变主线程执行的时候,进行日志的记录
Three tips for you to successfully get started with 3D modeling
图解 Canvas 入门
【LeetCode】双指针题解汇总
How to burn the KT148A voice chip into the chip through the serial port and the tools on the computer
Couple Holding Hands [Greedy & Abstract]
随机推荐
STC89C52RC的P4口的应用问题
Chinese and Japanese color style
进程间通信和线程间通信
软件测试面试题:系统测试的策略有?
What is next-generation modeling (with learning materials)
Mathematical Principles of Matrix
ansible学习笔记分享-含剧本示例
Essential knowledge for entry-level 3D game modelers
TinyMCE disable escape
电子行业MES管理系统的主要功能与用途
【云原生--Kubernetes】Pod控制器
数据类型及输入输出初探(C语言)
Statistical words (DAY 101) Huazhong University of Science and Technology postgraduate examination questions
软件测试面试题:黑盒测试、白盒测试以及单元测试、集成测试、系统测试、验收测试的区别与联系?
Getting started with 3D modeling for games, what modeling software can I choose?
E - Many Operations (按位考虑 + dp思想记录操作后的结果
IDEA 文件编码修改
ARC129E Yet Another Minimization 题解 【网络流笔记】
关于我仔细检查审核过关于工作人员页面,返回一个所属行业问题
could not build server_names_hash, you should increase server_names_hash_bucket_size: 32