funcpartition(sstring)[][]string{n:=len(s)dp:=make([][]bool,n)fori:=0;i<n;i++{dp[i]=make([]bool,n)forj:=0;j<=i;j++{dp[i][j]=true}}fori:=n-2;i>=0;i--{forj:=i+1;j<n;j++{ifs[i]==s[j]&&dp[i+1][j-1]{dp[i][j]=true}}}varans[][]stringvartmp[]stringvarbacktrackingfunc(idxint)backtracking=func(idxint){ifidx>=n{// replica := make([]string, len(tmp))
// copy(replica, tmp)
// ans = append(ans, replica)
// replace above three lines with the following one lines
ans=append(ans,append([]string(nil),tmp...))return}forj:=idx;j<n;j++{ifdp[idx][j]{tmp=append(tmp,s[idx:j+1])backtracking(j+1)tmp=tmp[:len(tmp)-1]}}}backtracking(0)returnans}