Let ' s play a traditional game Nim. You and I is seated across a table and we have a hundred stones on the table (we know the number of stones exactly). We play in turn and at each turn, you or I can remove over to a four-stones from the heap. You play first and the one who removed the last stone loses.
The this game has a winning strategy. To see this, your first remove four stones and leave stones. No matter how I play, I'll end up with leaving 92-95 stones. Then you'll in turn leave stones to me (verify this is always possible). This is leave 5k+1 stones for me and finally I get the last stone, sigh. If we initially had 101 stones, on the other hand, I had a winning strategy and you were doomed to lose.
Let ' s generalize the game a little bit. First, let's make it a team game. Each team has n players and the 2n players is seated around the table, with each player have opponents at both sides. Turn around the table so the the teams play alternately. Second, let's vary the maximum number of stones each player can take. That's, each player have his/her own maximum number of stones he/she can take at each turn (the minimum are always one). So the game was asymmetric and may even was unfair.
In general, when played between-teams of experts, the outcome of a game is completely determined by the initial number of stones and the maximum number of stones each player can be in each turn. In the other words, the either team has a winning strategy.
You are the Head-coach of a team. In each game, the umpire shows both teams the initial number of stones and the maximum number of stones each player can ta Ke at each turn. Your team plays first. Your job is, given those numbers, to instantaneously judge whether Your team have a winning strategy.
Incidentally, there is a rumor that captain the future and her officers of the Hakodate-maru love this game, and they are killing Their time playing it during their missions. You wonder where the stones is? Well, they does not has stones but does has plenty of balls in the fuel containers!
The memory search will be over.
Sensory memory Search is more useful than DP in some topics
such as this problem, with the memory of the search time complexity of the same
But if the DP does not know in what order to engage in ...
Program poj2068;varN,s,i:longint; f:array[-1.. -,-1..10010]of Longint; a:array[-1.. -]of longint;procedure dfs (i,j:longint);varK:longint;beginiff[i,j]<>-1Then exit; F[I,J]:=0; fork:=1To A[i] Do ifk<=J THEN begin DFS (i mod n+1, J-k); ifF[i MoD n+1, j-k] =0Then begin F[I,J]:=1; Break; End End;end;begin read (n); whileN<>0 Dobegin read (s); fori:=1To2*n Doread (a[i]); Readln;n:=n <<1; Fillchar (F,sizeof(f),255); fori:=1to n DoF[i,0]:=1; DFS (1, s); Writeln (f[1, S]); Read (n); End;end.
[POJ2068] Nim Problem Solving Report