using System; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); this.Length = inpt[0]; if(inpt[1] == 0) { long ans = 1; for(int i=2; i<=this.Length; i++) { ans*=i; ans = ans % MOD; } Console.WriteLine(ans); } else { this.NumList = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).OrderBy(a=>a).ToArray(); int maxKeta = Convert.ToString(this.NumList.Max(), 2).Length; char[] arr = new char[maxKeta].Select(a=>' ').ToArray(); foreach(long item in this.NumList.OrderByDescending(a=>a)) { string tmp = Convert.ToString(item, 2); for(int i=0; i dic = new Dictionary(); private long GetAns(long selected, long flags) { if(dic.ContainsKey(selected)) { return dic[selected]; } long flags2 = flags; for(int i=0; i this.NumList[i]) { dic[selected] = 0; return 0; } string selStr = Convert.ToString(selected, 2); string numStr = Convert.ToString(this.NumList[i], 2); selStr = selStr.PadLeft(numStr.Length, '0'); numStr = numStr.PadLeft(selStr.Length); bool flag = true; for(int j=numStr.Length -1; j>=0; j--) { if(numStr[j] == '0' && selStr[j] != '0') { flag = false; break; } } if(!flag) { dic[selected] = 0; return 0; } } if(selected == ((long)1<0) { continue; } ans+=this.GetAns(selected+key, flags2); ans = ans % MOD; } this.dic[selected] = ans; return ans; } private const long MOD = 1000000000 + 7; private int Length = 0; private long[] NumList; public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 10 3 5 1 "; public static string ReadLine() { if(IsDebug) { if(SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }