凑算式 dfs
来源:互联网 发布:php 统计在线人数代码 编辑:程序博客网 时间:2024/06/10 00:15
B DEF
A + — + ——- = 10
C GHI
(如果显示有问题,可以参见【图1.jpg】)
这个算式中A~I代表1~9的数字,不同的字母代表不同的数字。
比如:
6+8/3+952/714 就是一种解法,
5+3/1+972/486 是另一种解法。
这个算式一共有多少种解法?
注意:你提交应该是个整数,不要填写任何多余的内容或说明性文字。
思路:
只是比dfs全排列多了一个比较等式的步骤
代码:
#include<iostream>#include<algorithm>using namespace std;int a[10]={0},v[10]={0},cnt=0;int js(){int x,y;x=a[4]*100 + a[5]*10 + a[6];y=a[7]*100 + a[8]*10 + a[9];if (a[1]*a[3]*y + y*a[2] + a[3]*x == 10*a[3]*y) return 1;return 0;}int dfs(int n){int i,j;for (i=1;i<=9;i++){if (!v[i]){v[i]=1;a[n]=i;if (n<9) { dfs(n+1); }else { if (js()) cnt++; } v[i]=0; }}}int main(){dfs(1);cout<<cnt;return 0;}
0 0
- 凑算式 dfs
- 蓝桥杯 神奇算式 dfs
- 凑算式
- 凑算式
- 凑算式
- 凑算式
- 凑算式
- 凑算式
- 凑算式
- 凑算式
- 凑算式
- 凑算式
- 凑算式
- 凑算式
- 凑算式
- 凑算式
- 蓝桥杯 填符号凑算式 趣味运算 DFS枚举 字符串处理
- [dfs(深度优先搜索)]简单类题目 2016年蓝桥杯省赛题第三题——凑算式
- curl模拟post请求提交
- vs如何新建项目
- liunx之sed命令详解
- log4j+logback+slf4j的关系与调试
- Fiddler界面简介
- 凑算式 dfs
- 网络小故障-20170204
- Git 本地提交
- Codeforces 514C Watto and Mechanism【字典树+Dfs】好题!
- 多对多关联映射原理
- PHP编程效率的20个要点
- Redux 莞式教程
- 这个是没有效果的
- node.js实战学习笔记02--扩展事件监听器实现文件监听