## TreePlanting Level 2 Solution

My first post, from Veracruz,Mexico

--- My optimized code
public class TreePlanting
{
public long countArrangements(int total, int fancy)
{
String s;
int c=0,c1;

// 0 is plain, 1 is fancy
for (short x = 0; x<Math.pow(2,total); x++)
{
s = Integer.toBinaryString(x);
c1 = 0;
if (s.indexOf( "11" ) == -1)
for (short y = 0; y < s.length(); y++ )
if (s.startsWith("1",y))
c1 ++;
if (c1 == fancy)
c++;
}
return c;
}
}

--- My Original Idea
Instituto Tecnológico de Veracruz
Veracruz, México
21 años.
*/

import java.util.Vector;

public class TreePlanting
{
public long countArrangements(int total, int fancy)
{
Vector v = new Vector(1,2);
String s;
int c1;

// 0 is plain, 1 is fancy -
for (short x = 0; x<Math.pow(2,total); x++)
{
s = Integer.toBinaryString(x);
c1 = 0;
if (s.indexOf( "11" ) == -1)
for (short y = 0; y < s.length(); y++ )
if (s.startsWith("1",y))
c1 ++;
if (c1 == fancy)
}
return v.size();
}
TreePlanting()
{
System.out.println( countArrangements(4,2) );
System.out.println( countArrangements(3,1) );
System.out.println( countArrangements(4,3) );
System.out.println( countArrangements(10,4) );
}

static public void main(String[] a)
{ TreePlanting t = new TreePlanting();
}
}