当前位置:网站首页>[diary of supplementary questions] [2022 Niuke summer multi school 2] l-link with level editor I
[diary of supplementary questions] [2022 Niuke summer multi school 2] l-link with level editor I
2022-07-28 11:54:00 【cls1277】
Pro
https://ac.nowcoder.com/acm/problem/239349
Sol
With f i , j f_{i,j} fi,j Said in the first i The world is... In the end j A little bit , Which world can we start from at the latest .
State transition equation : If there is one in a world x->y The edge of , that f i , y = m a x ( f i − 1 , y , f i − 1 , x ) f_{i,y}=max(f_{i-1,y},f_{i-1,x}) fi,y=max(fi−1,y,fi−1,x), The first dimension is only related to the previous world , You can use the rolling array to optimize .
The difficulty of this problem lies in the following code :f[(i-1)&1][1] = i;Fo(j,1,m) f[i&1][j] = f[(i-1)&1][j]; And f[i&1][1] = i; Fo(j,2,m) f[i&1][j] = f[(i-1)&1][j]; Is it equivalent .
Why do you think so ? Because it's easy to understand , The first i The third in the world 1 The number point can be determined by i-1 The third in the world 1 It's time to come , I mistakenly think here f[(i-1)&1][1] = i; Just right f i , x f_{i,x} fi,x Assign initial value to , So I will write the code of the latter .
In fact, through testing the sample and careful debugging, we can find , This is not just about assignment , And it is also related to the update below , Therefore, the understanding here can be : The first i A world can be the beginning of the whole level , Arrive in this world at this time 1 The latest world at point is i. Why don't you consider taking the 1 Node number as the start ? Actually, I've finished thinking about it :
Suppose that in the front of a certain world 1 Node as the beginning of the level , If every world in front chooses 1 Node is no. , Until you select to i A world 1 Node is no. , At this time, it's better to directly select the i The number node of the world is better ; If every world ahead has a path to move , Then arrive at the i The node number of universal time must not be 1, That is, in the interval [2,m] It must contain the previous world 1 Node number as the starting case . Therefore, we need a key code f[(i-1)&1][1] = i;
Code
//By cls1277
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define Fo(i,a,b) for(LL i=(a); i<=(b); i++)
#define Ro(i,b,a) for(LL i=(b); i>=(a); i--)
#define Eo(i,x,_) for(LL i=head[x]; i; i=_[i].next)
#define Ms(a,b) memset((a),(b),sizeof(a))
#define endl '\n'
// const LL maxn = ;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("data.txt","r",stdin);
#endif
LL n, m, ans=INT_MAX; cin>>n>>m;
vector<vector<LL>> f(2, vector<LL>(m+1, -INT_MAX));
Fo(i,1,n) {
LL l; cin>>l;
f[(i-1)&1][1] = i;
Fo(j,1,m) f[i&1][j] = f[(i-1)&1][j];
// f[i&1][1] = i;
// Fo(j,2,m) f[i&1][j] = f[(i-1)&1][j];
Fo(j,1,l) {
LL x, y; cin>>x>>y;
f[i&1][y] = max(f[i&1][y], f[(i-1)&1][x]);
if(y==m&&f[i&1][m]!=-INT_MAX) ans = min(ans, i-f[i&1][m]+1);
}
}
cout<<(ans==INT_MAX?-1:ans);
return 0;
}
边栏推荐
- Several reincarnation stories
- 可视化大型时间序列的技巧。
- Service workers let the website dynamically load webp pictures
- Deployment and use of Minio distributed object storage
- Update dev (development version) of the latest win11
- mysql(8.0.16版)命令及说明
- Unity鼠标带动物体运动的三种方法
- [pyGame practice] when the end of the world comes, how long can you live in a cruel survival game that really starts from scratch?
- Database advanced learning notes - storage structure
- Digital twin rail transit: "intelligent" monitoring to clear the pain points of urban operation
猜你喜欢

14. User web layer services (II)

Unity鼠标带动物体运动的三种方法
![Full version of H5 social chat platform source code [complete database + complete document tutorial]](/img/3f/03239c1b4d6906766348d545a4f234.png)
Full version of H5 social chat platform source code [complete database + complete document tutorial]

Understand how to prevent tampering and hijacking of device fingerprints

Four advantages of verification code to ensure mailbox security

强缓存、协商缓存具体过程
![[general database integrated development environment] Shanghai daoning provides you with Aqua Data Studio downloads, tutorials, and trials](/img/46/830b7703ae7cbfa6051137061560c2.png)
[general database integrated development environment] Shanghai daoning provides you with Aqua Data Studio downloads, tutorials, and trials

consul安装与配置

Xiaoshuidi 2.0 website navigation network template

Six papers that must be seen in the field of target detection
随机推荐
Detailed explanation of boost official website search engine project
Anonymous subclass objects of abstract classes
The reflect mechanism obtains the attribute and method information of class
A lock faster than read-write lock. Don't get to know it quickly
Develop your own NPM package from 0
Full version of H5 social chat platform source code [complete database + complete document tutorial]
Outlook suddenly becomes very slow and too laggy. How to solve it
15、用户web层服务(三)
Database advanced learning notes - storage structure
PFP会是数字藏品的未来吗?
如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然
[极客大挑战 2019]BabySQL-1|SQL注入
LabVIEW AI visual Toolkit (non Ni vision) download and installation tutorial
How async await implements concurrency
一些多参数函数的具体作用
How to deal with invalid objects monitored by Oracle every day in the production environment?
15. User web layer services (III)
Globalthis is not defined solution
[pyGame practice] the super interesting bubble game is coming - may you be childlike and always happy and simple~
A new mode of one-stop fixed asset management