提交时间:2021-05-27 22:07:48
运行 ID: 20026
#include<iostream> #include<cmath> using namespace std; int a[21],ans=0; int n,k; bool check(int x) { int i,t=0,xx,ge,cj,sum=0; xx=x; while (xx){ t++;xx/=10; } xx=x; while (xx){ ge=xx%10;cj=1; for (i=1;i<=t;++i){ cj*=ge; } sum+=cj; xx/=10; } if(sum==x)return 1; else return 0; } void search(int t,int s,int l) { if(t==k){if(check(s))ans++;} else for(int i=l;i<=n;i++) search(t+1,s+a[i],i+1); } int main() { cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i]; search(0,0,1); cout<<ans; return 0; }