using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace COMP252A1
{
class Program
{
static void Main(string[] args)
{
Console.Write("n=");
int n = int.Parse(Console.ReadLine());
Console.Write("w=");
int w = int.Parse(Console.ReadLine());
List<char[]> seq = piano(n, w);
foreach (char[] cs in seq)
Console.WriteLine(cs);
Console.Read();
}
static void Q1()
{
int[] gray = new int[256];
for (int i = 0; i < 256; i++)
{
for (int j = 128; j > 0; j >>= 1)
{
gray[i] = gray[i] | ((((i & j) != 0) ^ ((i & (j << 1)) != 0)) ? j : 0);
Console.Write((((i & j) != 0) ^ ((i & (j << 1)) != 0)) ? "#" : "-");
//Console.Write(((i & j) != 0) ? 1 : 0);
}
Console.WriteLine();
}
//for (int i = 128; i > 0; i >>= 1)
// Console.Write(((gray[50] & i) != 0) ? 1 : 0);
Console.WriteLine(Array.IndexOf<int>(gray, Convert.ToInt32("11111111", 2)));
}
static List<char[]> piano(int n, int w)
{
List<char[]> res = new List<char[]>();
if (w == 0)
{
char[] resc = new char[n];
for (int i = 0; i < n; i++) resc[i] = '0';
res.Add(resc);
return res;
}
else if (w == 1)
{
char[] resc;
for (int i = 0; i < n; i++)
{
resc = new char[n];
for (int j = 0; j < n; j++) resc[j] = '0';
resc[i] = '1';
res.Add(resc);
}
return res;
}
else if (n == w)
{
char[] resc = new char[n];
for (int i = 0; i < n; i++) resc[i] = '1';
res.Add(resc);
return res;
}
else
{
List<char[]> resl;
resl = piano(n - 1, w);
foreach (char[] cs in resl)
{
char[] cx = (char[])cs.Clone();
Array.Resize<char>(ref cx, n);
cx[n - 1] = '0';
res.Add(cx);
}
resl = piano(n - 2, w - 1);
resl.Reverse();
foreach (char[] cs in resl)
{
char[] cx = (char[])cs.Clone();
Array.Resize<char>(ref cx, n);
cx[n - 2] = '0';
cx[n - 1] = '1';
res.Add(cx);
}
resl = piano(n - 2, w - 2);
foreach (char[] cs in resl)
{
char[] cx = (char[])cs.Clone();
Array.Resize<char>(ref cx, n);
cx[n - 2] = cx[n - 1] = '1';
res.Add(cx);
}
return res;
}
}
}
}