Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- /// <summary>
- /// I can't figure out how to backtrack and print the solution
- /// </summary>
- namespace _678.Problem_10
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = 5;
- int m = 16;
- int sum = n;
- Queue<int> subsetFinder = new Queue<int>();
- subsetFinder.Enqueue(n);
- while (sum < m)
- {
- sum = subsetFinder.Dequeue();
- // Console.Write(sum + " ");
- if ((sum * 2) <= m && !subsetFinder.Contains(sum * 2))
- {
- subsetFinder.Enqueue(sum * 2);
- }
- if ((sum + 2) <= m && !subsetFinder.Contains(sum + 2))
- {
- subsetFinder.Enqueue(sum + 2);
- }
- if ((sum + 1) <= m && !subsetFinder.Contains(sum + 1))
- {
- subsetFinder.Enqueue(sum + 1);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement