public class Test6 {
public static void main(String[] args) throws Exception {
print(2, 5, 10, new StringBuilder());
}
public static void print(int wine,int shop,int flower,StringBuilder builder){
if(wine==0&&shop==0&&flower==0&&builder.charAt(builder.length()-1)=='b'){
System.out.println(builder);
}else if(shop<0||flower<0) {
return;
}
print(wine*2, shop-1, flower, builder.append('a'));
builder.deleteCharAt(builder.length()-1);
print(wine-1, shop, flower-1, builder.append('b'));
builder.deleteCharAt(builder.length()-1);
}
}
|