class Go{
List<List<String>> result = new ArrayList<>();
List<String> list = new ArrayList<>();
char[] arr;
String s;
void core(int index){
if (index == arr.length){
result.add(new ArrayList<>(list));
return;
}
for (int i = index; i < arr.length; i++){
if (ishw(index,i)){
list.add(s.substring(index,i + 1));
core(i + 1);
list.remove(list.size() - 1);
}
}
}
boolean ishw(int left,int right){
int L = left,R = right;
while (L <= R){
if (arr[L++] != arr[R--]){
return false;
}
}
return true;
}
public List<List<String>> partition(String s) {
arr = s.toCharArray();
this.s = s;
core(0);
return result;
}
}
public class Cutpalindrome {
public static void main(String[] args) {
Go g = new Go();
System.out.println(g.partition("aacb"));
}
}