Codeforces Beta Round 40(Div. 2)
D
兵卒
Pawn
Codeforces
1900
原题
← CE →

兵卒AI (CI翻译)

On some square in the lowest row of a chessboard a stands a pawn. It has only two variants of moving: upwards and leftwards or upwards and rightwards. The pawn can choose from which square of the lowest row it can start its journey. On each square lay from 0 to 9 peas. The pawn wants to reach the uppermost row having collected as many peas as possible. As there it will have to divide the peas between itself and its $*k*$ brothers, the number of peas must be divisible by $*k* + 1$. Find the maximal number of peas it will be able to collect and which moves it should make to do it.

棋盘的最底行中的某个格子上有一个兵。它只有两种移动方式:向上并向左,或向上并向右。兵可以选择最底行中的任意一个格子作为起点。棋盘上的每个格子中放有 $0$ 到 $9$ 颗豆子。兵希望在收集尽可能多的豆子后到达最顶行。由于到达那里后,它必须将豆子与它的 $*k*$ 个兄弟平分,因此豆子的总数必须能被 $*k* + 1$ 整除。请找出它能够收集的最大豆子数,以及为此应采取的移动方式。AI (CI翻译)

The pawn cannot throw peas away or leave the board. When a pawn appears in some square of the board (including the first and last square of the way), it necessarily takes all the peas.

兵不能丢弃豆子,也不能离开棋盘。当兵出现在棋盘中的某个格子上(包括路径的第一个和最后一个格子)时,它必须收集该格子中的所有豆子。AI (CI翻译)

Input

输入格式

AI (CI翻译)

The first line contains three integers $*n*$, $*m*$, $*k*$ ($2 ≤ *n*, *m* ≤ 100, 0 ≤ *k* ≤ 10$) — the number of rows and columns on the chessboard, the number of the pawn's brothers. Then follow $*n*$ lines containing each $*m*$ numbers from 0 to 9 without spaces — the chessboard's description. Each square is described by one number — the number of peas in it. The first line corresponds to the uppermost row and the last line — to the lowest row.

第一行包含三个整数 $*n*$、$*m*$、$*k*$($2 ≤ *n*, *m* ≤ 100$,$0 ≤ *k* ≤ 10$),分别表示棋盘的行数和列数,以及兵的兄弟数。接下来是 $*n*$ 行,每行包含 $*m*$ 个无空格的、范围从 0 到 9 的数字,表示棋盘的布局。每个格子由一个数字表示,即该格子中的豆子数。第一行对应最顶行,最后一行对应最底行。AI (CI翻译)

Output

输出格式

AI (CI翻译)

If it is impossible to reach the highest row having collected the number of peas divisible by $*k* + 1$, print -1.

如果无法到达最顶行并收集到能被 $*k* + 1$ 整除的豆子数,输出 -1。AI (CI翻译)

Otherwise, the first line must contain a single number — the maximal number of peas the pawn can collect given that the number must be divisible by $*k* + 1$. The second line must contain a single number — the number of the square's column in the lowest row, from which the pawn must start its journey. The columns are numbered from the left to the right with integral numbers starting from $1$. The third line must contain a line consisting of $*n* - 1$ symbols — the description of the pawn's moves. If the pawn must move upwards and leftwards, print L, if it must move upwards and rightwards, print R. If there are several solutions to that problem, print any of them.

否则,第一行输出一个整数,即在豆子总数必须能被 $*k* + 1$ 整除的条件下,兵能够收集的最大豆子数。第二行输出一个整数,即兵必须从最底行的第几列开始移动。列从左到右编号,编号从 $1$ 开始。第三行输出一行由 $*n* - 1$ 个字符组成的字符串,表示兵的移动方式。如果兵必须向上并向左移动,输出 L;如果必须向上并向右移动,输出 R。如果有多个解,输出任意一个即可。 AI (CI翻译)

样例

Input #1
3 3 1
123
456
789
Output #1
16
2
RL
InputCopy OutputCopy
Input #2
3 3 0
123
456
789
Output #2
17
3
LR
InputCopy OutputCopy
Input #3
2 2 10
98
75
Output #3
-1
InputCopy OutputCopy
题目信息
题号
41D
时间限制
2 s
内存限制
256 MB
标签
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。