#include<bits/stdc++.h>
using namespace std;
int n,k,ans=0;
int a[25],c[25],d[25];
bool b[25];
int isshui(int n) {
int temp=n;
int t[20];
int cn=0;
while(temp) {
t[++cn]=temp%10;
temp=temp/10;
}
int s=0;
for(int i=1; i<=cn; i++) {
s=s+pow(t[i],cn);
}
if(s==n)
return 1;
else
return 0;
}
void myprint() {
int temp=0;
for(int i=1; i<=k; i++) {
temp+=d[i];
}
ans+=isshui(temp);
}
void search(int step) {
for(int i=1; i<=n; i++) {
if(!b[i]&&i>c[step-1]) {
b[i]=true;
c[step]=i;
d[step]=a[i];
if(step==k) {
myprint();
} else {
search(step+1);
}
b[i]=false;
}
}
}
int main() {
cin>>n>>k;
for(int i=1; i<=n; i++) {
cin>>a[i];
}
search(1);
cout<<ans;
return 0;
}
【提高】水仙花数(2010江苏省)
最新推荐文章于 2024-09-06 10:38:06 发布