牛式

2017-08-17  本文已影响0人  书臆
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>

using namespace std ;

int a[10],f[10],n,ans;
bool flag[10];

void dfs(int k){
    if(k==5){
        int tmp1=100*f[1]+10*f[2]+f[3];
        int tmp2=tmp1*f[4];
        int tmp3=tmp1*f[5];
        if(tmp2>=1000 || tmp3>=1000)return ;
        while(tmp2){if(!flag[tmp2%10])return ;tmp2/=10;}
        while(tmp3){if(!flag[tmp3%10])return ;tmp3/=10;}
        tmp2=tmp1*f[4];
        tmp3=tmp1*f[5];
        int sum=tmp2*10+tmp3;
        if(sum>=10000)return ;
        while(sum){if(!flag[sum%10])return ;sum/=10;}
        ans++;
        return ;
    }
    for(int i=1;i<=n;i++)f[k+1]=a[i],dfs(k+1);
    
    
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        flag[a[i]]=1;
    }
    dfs(0);
    printf("%d\n",ans);
    return 0;
}
上一篇 下一篇

猜你喜欢

热点阅读