Skip to content

Instantly share code, notes, and snippets.

@pb10005
Created August 30, 2018 10:46
Show Gist options
  • Save pb10005/f8e434bdaa5fff1bd9a618c41cc8f378 to your computer and use it in GitHub Desktop.
Save pb10005/f8e434bdaa5fff1bd9a618c41cc8f378 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
public static void Main(){
// Your code here!
var N = int.Parse(Console.ReadLine());
var array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
CountUp game = new CountUp(N, array);
game.Solve();
Array.Reverse(game.Grundy);
Console.WriteLine(string.Join(",",game.Grundy));
}
}
public class CountUp{
public CountUp(int goal, int[] array){
this.goal = goal;
this.nums = array;
grundy = new int[goal+1];
}
int[] grundy;
public int[] Grundy{
get{
return grundy;
}
}
int[] nums;
int goal;
public void Solve(){
CalcGrundy(0);
}
int CalcGrundy(int n){
int max = 0;
HashSet<int> g = new HashSet<int>();
foreach(int num in nums){
int tmp = n + num;
if(tmp > goal) continue;
else if(tmp == goal){
g.Add(0);
}
else{
if(grundy[tmp] == default(int)){
g.Add(CalcGrundy(tmp));
}
else{
g.Add(grundy[tmp]);
}
}
}
for(int i=0;;i++){
if(!g.Contains(i)){
grundy[n] = i;
return i;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment