#Q249. 「一本通 6.7 练习 4」S-Nim
「一本通 6.7 练习 4」S-Nim
Description
Original problem from: HDU 1536
Two players are playing a game with the following rules: There are piles of stones, with stones respectively. In each turn, a player must take some stones from one pile, but the number of stones taken must be one of the predefined values in the set . The player who cannot make a move loses.
Input Format
Multiple test cases.
For each test case, the first line contains an integer , followed by integers representing ;
The second line contains an integer , indicating that game states will be provided;
The next lines each start with an integer , followed by integers representing .
If , it signifies the end of input.
Output Format
For each test case, output a string of characters, where each character indicates whether the corresponding game state is a winning position (W) or a losing position (L).
Sample 1
2 2 5
3
2 5 12
3 2 4 7
4 2 3 7 12
5 1 2 3 4 5
3
2 5 12
3 2 4 7
4 2 3 7 12
0
LWW
WWL
Data Range and Hint
For all data, , and .