using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input3"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("2"); WillReturn.Add("1 2"); //4 //0=0 //1=0 XOR 1 //2=0 XOR 2 //3=0 XOR 1 XOR 2 //の4種類の値を作ることができます。 } else if (InputPattern == "Input2") { WillReturn.Add("6"); WillReturn.Add("1 1 4 5 1 4"); //4 //6つ整数が与えられても4種類しか作れない場合もあります } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); //0 XOR 0 XOR 0 = 0 //0 XOR 1 XOR 1 = 0 //1 XOR 0 XOR 0 = 1 //1 XOR 1 XOR 1 = 1 //よって、 //A XOR B XOR B = A なので、 //重複した値は、Distinctしておく int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).Distinct().ToArray(); //作成可否[整数]なDP表 var PrevDP = new bool[16384 * 2 + 1]; PrevDP[0] = true; foreach (int EachA in AArr) { var CurrDP = (bool[])PrevDP.Clone(); for (int I = 0; I <= PrevDP.GetUpperBound(0); I++) { if (PrevDP[I] == false) continue; int wkInd = EachA ^ I; CurrDP[wkInd] = true; } PrevDP = CurrDP; } Console.WriteLine(PrevDP.Count(X => X)); } }