knightnemo commited on
Commit
0b2b7b9
·
verified ·
1 Parent(s): 031d9f0

Upload code_segments/segment_230.txt with huggingface_hub

Browse files
Files changed (1) hide show
  1. code_segments/segment_230.txt +27 -0
code_segments/segment_230.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Consider a grid graph with $n$ rows and $n$ columns. Let the cell in row $x$ and column $y$ be $(x,y)$. There exists a directed edge from $(x,y)$ to $(x+1,y)$, with non-negative integer value $d_{x,y}$, for all $1\le x < n, 1\le y \le n$, and there also exists a directed edge from $(x,y)$ to $(x,y+1)$, with non-negative integer value $r_{x,y}$, for all $1\le x \le n, 1\le y < n$.
2
+
3
+ Initially, you are at $(1,1)$, with an empty set $S$. You need to walk along the edges and eventually reach $(n,n)$. Whenever you pass an edge, its value will be inserted into $S$. Please maximize the MEX$^{\text{∗}}$ of $S$ when you reach $(n,n)$.
4
+
5
+ $^{\text{∗}}$The MEX (minimum excluded) of an array is the smallest non- negative integer that does not belong to the array. For instance:
6
+
7
+ * The MEX of $[2,2,1]$ is $0$, because $0$ does not belong to the array. * The MEX of $[3,1,0,1]$ is $2$, because $0$ and $1$ belong to the array, but $2$ does not. * The MEX of $[0,3,1,2]$ is $4$, because $0, 1, 2$, and $3$ belong to the array, but $4$ does not.
8
+
9
+ Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1\le t\le100$). The description of the test cases follows.
10
+
11
+ The first line of each test case contains a single integer $n$ ($2\le n\le20$) — the number of rows and columns.
12
+
13
+ Each of the next $n-1$ lines contains $n$ integers separated by single spaces — the matrix $d$ ($0\le d_{x,y}\le 2n-2$).
14
+
15
+ Each of the next $n$ lines contains $n-1$ integers separated by single spaces — the matrix $r$ ($0\le r_{x,y}\le 2n-2$).
16
+
17
+ It is guaranteed that the sum of all $n^3$ does not exceed $8000$.
18
+
19
+ For each test case, print a single integer — the maximum MEX of $S$ when you reach $(n,n)$.
20
+
21
+ In the first test case, the grid graph and one of the optimal paths are as follows:
22
+
23
+ ![](CDN_BASE_URL/70956fd41a5289db10b3b0bb41d0efae)
24
+
25
+ In the second test case, the grid graph and one of the optimal paths are as follows:
26
+
27
+ ![](CDN_BASE_URL/c6a0ac2a80551ddd517e35658fa66438)