1. 程式人生 > >Codeforces Round #406 (Div. 2):C. Berzerk(記憶化搜尋解決博弈問題)

Codeforces Round #406 (Div. 2):C. Berzerk(記憶化搜尋解決博弈問題)

Each one of them has a set of numbers between 1 and n - 1 (inclusive). Rick's set is s1 with k1 elements and Morty's is s2 with k2 elements. One of them goes first and the player changes alternatively. In each player's turn, he should choose an arbitrary number like x from his set and the monster will move to his x

-th next object from its current position (clockwise). If after his move the monster gets to the black hole he wins.

Your task is that for each of monster's initial positions and who plays first determine if the starter wins, loses, or the game will stuck in an infinite loop. In case when player can lose or make game infinity, it more profitable to choose infinity game.