题意有问题 明明应该是组间无序 却写成组内无序 坑的一批啊

先全排列 然后将每个排列都分成数份 因为组间无序 所以先排个序再去重

写这道题有两个智障错误 第一是忘开longlong 第二是排序时直接对dfs用的序列排序。。

还有注意遇到当前位置是0时要特殊处理

 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

map <string,bool> mp;
ll ary[10],pre[10],gou[10];
int ans;

bool judge(ll val)
{
ll tmp;
tmp=sqrt(val);
return tmp*tmp==val;
}

string solve(ll val)
{
string res;
if(val==0) return "0";
res="";
while(val>0){
res+='0'+val%10;
val/=10;
}
return res;
}

void dfs(int cur,int cnt)
{
string s;
ll tmp;
int i;
if(cur==10){
//sort(pre,pre+cnt);
for(i=0;i<cnt;i++) gou[i]=pre[i];
sort(gou,gou+cnt);
s="";
for(i=0;i<cnt;i++){
s+=solve(gou[i]);
s+=".";
}
if(!mp[s]){
mp[s]=1;
ans++;
}
return;
}
if(ary[cur]==0){
pre[cnt]=0;
dfs(cur+1,cnt+1);
}
else{
tmp=0;
for(i=cur;i<10;i++){
tmp=10ll*tmp+ary[i];
if(judge(tmp)){
pre[cnt]=tmp;
dfs(i+1,cnt+1);
}
}
}
}

int main()
{
int i;
for(i=0;i<10;i++) ary[i]=i;
do{
dfs(0,0);
}
while(next_permutation(ary,ary+10));
printf("%d\n",ans);
return 0;
}