No.506 Limited Japari Buns
Problem Statement
You are now in an area called a "chihou" in a zoo called Japari Park.
This chihou is represented as a grid of $(H+1)*(W+1)$ lattice points, spanning $H$ meters in the east-west direction and $W$ meters in the north-south direction, and you are now at $(0,0)$. You are trying to reach $(H,W)$ by moving only east and north.
Throughout this chihou there are human-shaped animals called Friends; it is known that each one is named $N[i]$ and is at $(x[i],y[i])$. Also, there is at most 1 Friend at any one location.
You cannot pass through a location where a Friend is, but it becomes passable if you give that Friend one bun called a Japari bun.
There is never a Friend at the start or the goal.
(Note: It was originally intended that there could be, but since none exist in the actual test cases and in view of the situation, it has been decided that there are none.)
Output the names of the Friends to give Japari buns to so that the number of shortest paths to $(H,W)$ is maximized, along with the number of paths modulo $1000000007$.
However, if $(H,W)$ cannot be reached, output 0. In all test cases, except when the goal cannot be reached or when you have no Japari buns, there is exactly one way that achieves the maximum number of paths.
Input
$H$ $W$ $K$ $P$ $x[1]$ $y[1]$ $N[1]$ $x[2]$ $y[2]$ $N[2]$ … $x[K]$ $y[K]$ $N[K]$
$H$ represents the east-west length of this chihou.
$W$ represents the north-south length of this chihou.
$K$ represents the number of Friends in this chihou.
$P$ represents the number of Japari buns you have.
$x[i]$,$y[i]$ means that the $i$-th Friend is at $(x[i],y[i])$.
$N[i]$ represents the name of the $i$-th Friend.
Only $N[i]$ is a string; all the others are integers.
$1≤H,W≤32$
$1≤K≤min(15,(H+1) \times (W+1) - 2)$
$0≤P≤K$
$0≤x[i]≤H$
$0≤y[i]≤W$
$(x[i],y[i])≠(x[j],y[j])$ when $i≠j$
(Only one of $x$ and $y$ may coincide.)
$(x[i],y[i]) \ne (0,0),(H,W)$
(There are no Friends at the start and the goal.)
$N[i]≠N[j]$ when $i≠j$
$N[i]$ consists of half-width lowercase English letters only and has between 1 and 10 characters, inclusive.
Except when the goal cannot be reached or when you have no Japari buns, there is exactly one way that achieves the maximum number of paths.
Output
On the first line, output the maximum number of shortest paths modulo $1000000007$.
Then output the names of the Friends you give Japari buns to, in the order they were given in the input, separated by newlines.
Finally, output a newline.
Sample
Sample 1
Input
1 2 1 1 0 1 serval
Output
3 serval
◯─G
│ │
サ─◯
│ │
S─◯
Giving a Japari bun to Serval (サ) increases the number of passable paths from 1 to 3.
Sample 2
Input
3 4 2 0 3 3 konoha 2 4 mimi
Output
0
Since you have no Japari buns, in this example you cannot reach the goal, so the answer is 0 paths.
Sample 3
Input
10 10 6 4 2 9 moose 1 8 chameleon 4 7 shoebill 5 8 porcupine 6 7 whiterhino 6 5 armadillo
Output
183928 shoebill porcupine whiterhino armadillo
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
0214sh7
ixmel