Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static bool fillUtil(int[] res, int curr, int n)
- {
- if (curr == 0) return true;
- int i;
- for (i = 0; i < 2 * n - curr - 1; i++)
- {
- if (res[i] == 0 && res[i + curr + 1] == 0)
- {
- res[i] = res[i + curr + 1] = curr;
- if (fillUtil(res, curr - 1, n))
- return true;
- res[i] = res[i + curr + 1] = 0;
- }
- }
- return false;
- }
- static void fill(int n)
- {
- int[] res = new int[2 * n];
- int i;
- for (i = 0; i < 2 * n; i++)
- res[i] = 0;
- if (fillUtil(res, n, n))
- {
- for (i = 0; i < 2 * n; i++)
- Console.Write(res[i]);
- }
- else
- Console.Write("Not Possible");
- }
- static void Main(string[] args)
- {
- Console.Write("3: ");
- fill(3);
- Console.Write("\n\n2: ");
- fill(2);
- Console.Write("\n4: ");
- fill(4);
- Console.Write("\n\n");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement