using System; using System.Collections.Generic; using System.Linq; namespace No10_1{ public class Program{ public static int n = Read(Convert.ToInt32); public static int total = Read(Convert.ToInt32); public static List an = ReadList(Convert.ToInt32); public static List[] dplist = new List[n + 1]; public static Stack stk = new Stack(); public static bool flag = an.All(x => x <= 3); public static void Main(string[] args){ for(var i = 0; i < dplist.Length; i++){ dplist[i] = new List(); } an.Insert(0, 0); an.Add(int.MaxValue); Solve(true, 0, 0); stk.Pop(); stk.Pop(); var result = ""; foreach(var s in stk){ result += s ? "+" : "*"; } Console.WriteLine(result); Console.ReadLine(); } public static bool Solve(bool op, int sum, int cnt){ if(sum == total && cnt == n + 1) return true; if(sum > total || cnt > n) return false; if(flag){ if(dplist[cnt].Contains(sum)) return false; dplist[cnt].Add(sum); } if(Solve(true, sum + an[cnt], cnt + 1)){ stk.Push(true); return true; } if(Solve(false, sum * an[cnt], cnt + 1)){ stk.Push(false); return true; } return false; } public static TOutput Read(Converter converter){ return converter(Console.ReadLine()); } public static List ReadList(Converter converter, char c = ' '){ return Console.ReadLine()?.Split(c).ToList().ConvertAll(converter); } } }