[USACO1.3]牛式 Prime Cryptarithm
2016-08-18 17:28
274 查看
[USACO1.3]牛式 Prime Cryptarithm
题目大意
给出一个固定的由‘*’组成的等式
然后给出n个一位的十进制数,将这些数填入这个等式,每个数可以填任意次,求方案数,这n个数中不存在0,不重复,所以最多只有9个
解法:
用深搜首先枚出前面的两个乘数,然后直接通过判断就可以了,因为后面的数可以通过前面得到
#include<cstdio> #include<cstring> #include<iostream> using namespace std; int n,a[20],p[10]; int f[10],sum,x1,y1,x2,y2,ans; void dfs(int k) { if(k==5) { x1=f[1]*100+f[2]*10+f[3]; x2=f[5]*x1;y2=f[4]*x1; if(x2>=1000||y2>=1000)return; while(x2){if(p[x2%10]==0)return;x2=x2/10;} while(y2){if(p[y2%10]==0)return;y2=y2/10;} x2=f[5]*x1;y2=f[4]*x1; sum=x2+y2*10; if(sum>=10000)return; while(sum){if(p[sum%10]==0)return;sum=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]),p[a[i]]=1; dfs(0); printf("%d\n",ans); return 0; }
相关文章推荐
- P1211 [USACO1.3]牛式 Prime Cryptarithm
- 【模拟】洛谷 P1211 [USACO1.3]牛式 Prime Cryptarithm
- 这压缩,太强了![USACO1.3]牛式 Prime Cryptarithm
- USACO1.3牛式 Prime Cryptarithm
- 【USACO1.3】牛式 Prime Cryptarithm
- USACO 1.3 Prime Cryptarithm
- USACO-Section1.3 Prime Cryptarithm
- USACO1.3.4 Prime Cryptarithm(牛式)
- USACO Section 1.3 : Prime Cryptarithm
- usaco 1.3 Prime Cryptarithm
- USACO Section 1.3: Prime Cryptarithm
- USACO 1.3 - Prime Cryptarithm(暴力枚举)
- USACO 1.3 Prime Cryptarithm
- USACO Section 1.3 Prime Cryptarithm
- USACO 1.3 Prime Cryptarithm
- USACO 1.3 Prime Cryptarithm
- USACO-Section1.3 Prime Cryptarithm
- USACO 1.3-Prime Cryptarithm
- USACO-Section 1.3 Prime Cryptarithm(枚举)
- USACO: Section 1.3 -- PROB Prime Cryptarithm