A7902 | Pawn
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
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.
输入格式
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.
输出格式
If it is impossible to reach the highest row having collected the number of peas divisible by $k+1$ , print -1.
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.
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.
输入输出样例
输入 #1
3 3 1 123 456 789
输出 #1
16 2 RL
输入 #2
3 3 0 123 456 789
输出 #2
17 3 LR
输入 #3
2 2 10 98 75
输出 #3
-1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted