题目链接:http://oj.ecustacm.cn/problem.php?id=1254
分析:
排列组合:
转动和翻转的情况:
转动:起点不固定,1234和2341是同一种方式
翻转:
对于是同一种情况
12个位置,3个位置放红色,4个位置放白色,其余的放黄色
是所有的情况
考虑转动:
因为有转动的情况,12个位置,每一个位置都可以当成起点,所以除以12
考虑翻转:
所有的情况中,包含上述翻转所列的情况,这两种其实是一种情况,这种情况是不对称所满足的,需要除以2
对于对称:
对称轴上,一红,一黄,其余两边各5个位置,从一侧5个位置中挑2个放白,剩余3个位置中挑1个放红,其余2个位置放黄
所以最终的公式为:
vector+string
代码:
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
vector<string>v;
string str="aaabbbbccccc";
int sum=0;
v.clear();
do
{
vector<string>::iterator it;
for(it=v.begin(); it!=v.end(); it++)
{
if((*it).find(str,0)!=string::npos)/*从vector容器0的位置开始寻找,看是否有和str一样的字符串,如果找到返回在容器中的位置*/
break;
}
if(it!=v.end())/*上面for循环中如果找到,执行break,表明字符串已经出现过*/
continue;
string str2=str+str;
v.push_back(str2);/*转动的情况*/
reverse(str2.begin(),str2.end());/*翻转的情况*/
v.push_back(str2);
sum++;
}
while(next_permutation(str.begin(),str.end()));
cout<<sum<<endl;
return 0;
}
The greatest test of courage on earth is to bear defeat without losing heart.