深度优先搜索(DFS)进行回文串划分

#include
#include 
#include 
using namespace std;

void CalcSubPalindrome(const string &str,int size,vector>&p)
{
	for (int i=0;i=0;i--)
	{
		p[i][i+1]=(str[i]==str[i+1]);
		for (int j=i+2;j(i,j)为回文串 */

void MinPalindrome(const string str,int size,int nStart,const vector>&p,
				   vector>&all,vector&solution)
{
	if (nStart>=size)
	{
		all.push_back(solution);
	}
	for (int i=nStart;i>p,int size)
{
	for (int i=0;isolution)
{
	for (int i=0;i>all)
{
	for (int i=0;i>p;
	p.resize(len);
	for (int i=0;i>all;//所有结果
	vector solution;//
	MinPalindrome(str,len,0,p,all,solution);
	cout<<"Count:"<

1 0 1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 1 0 1 0 0 0 0
0 0 0 0 1 0 0 1 0 0
0 0 0 0 0 1 1 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0 0 1
Count:16
a|b|a|c|d|c|c|d|a|a|
a|b|a|c|d|c|c|d|aa|
a|b|a|c|d|cc|d|a|a|
a|b|a|c|d|cc|d|aa|
a|b|a|c|dccd|a|a|
a|b|a|c|dccd|aa|
a|b|a|cdc|c|d|a|a|
a|b|a|cdc|c|d|aa|
aba|c|d|c|c|d|a|a|
aba|c|d|c|c|d|aa|
aba|c|d|cc|d|a|a|
aba|c|d|cc|d|aa|
aba|c|dccd|a|a|
aba|c|dccd|aa|
aba|cdc|c|d|a|a|
aba|cdc|c|d|aa|

你可能感兴趣的:(c++)