USACO-Section1.3 Prime Cryptarithm [搜索]
来源:互联网 发布:javascript实现trie树 编辑:程序博客网 时间:2024/06/05 15:26
2017-5-27
题目描述
给你几个数字,求出给定等式中数字都在这几个数中的数的个数
解答
深搜,深度只要到5即可
代码
/*ID: 18795871PROG: crypt1LANG: C++*/#include<iostream>#include<fstream>#include<cstring>using namespace std;ifstream fin("crypt1.in");ofstream fout("crypt1.out");bool f[10];int x[10],j,sum=0,p,q,r;int cal1(int n){ int r=0; while (n){ r++; n/=10; } return r;}bool cal2(int n){ while (n){ if (!f[n%10]) return false; n/=10; } return true;}bool res(){ p=(100*x[1]+10*x[2]+x[3])*x[5]; q=(100*x[1]+10*x[2]+x[3])*x[4]; r=10*q+p; if (cal1(p)==3&&cal2(p)&&cal1(q)==3&&cal2(q)&&cal1(r)==4&&cal2(r)) return true; return false;}void dfs(int step){ if (step==6){ if (res()){ sum++; } return ; } for (int i=1;i<=9;i++){ if (f[i]){ x[step]=i; dfs(step+1); } }}int main(){ int n,m; j=0; fin>>n; memset(f,false,sizeof(f)); memset(x,0,sizeof(x)); for (int i=1;i<=n;i++){ fin>>m; f[m]=true; } dfs(1); fout<<sum<<endl; return 0;}
阅读全文
1 0
- USACO-Section1.3 Prime Cryptarithm [搜索]
- USACO Section1.3 Prime Cryptarithm
- USACO-Section1.3 Prime Cryptarithm
- USACO-Section1.3 Prime Cryptarithm
- USACO-Section1.3Prime Cryptarithm[其他]
- USACO-Section1.3 Prime Cryptarithm【暴力枚举】
- USACO-Section1.3 Prime Cryptarithm [其他]
- usaco.section1.3.Prime Cryptarithm
- USACO 1.3.3 Prime Cryptarithm
- USACO Prime Cryptarithm Accepted
- Prime Cryptarithm(USACO)
- USACO 1.3-Prime Cryptarithm
- [USACO] Prime Cryptarithm
- USACO 1.3 Prime Cryptarithm
- USACO Prime Cryptarithm
- usaco Prime Cryptarithm
- [USACO]Prime Cryptarithm
- USACO Prime Cryptarithm 杂水题
- 重建二叉树
- 为么使用Redis及其产品定位 —— Redis学习笔记(二)
- 一点感想
- ThinkPHP学习笔记(二)-------一个放不开
- Redis内存使用优化与存储——学习笔记(三)
- USACO-Section1.3 Prime Cryptarithm [搜索]
- ThinkPHP学习总结--
- Ubuntu下查看Linux内核源码(vim+ctags)
- PHP函数——session_id()
- MySQL Replication(复制)基本原理----学习笔记
- Mysql_insert_id的一个缺陷 ——呃原来手册上写着
- MySQL 程序概述----读mysql手册笔记
- 一个JS题
- 数组模拟无限级分类及可伸缩——php&&js(jQuery)