当前位置:网站首页>结果填空 凑算式(DFS*C语言)
结果填空 凑算式(DFS*C语言)
2022-07-28 05:19:00 【小白鼠零号】
如图,这个算式中A~I代表1~9的数字,不同的字母代表不同的数字。

比如:
6+8/3+952/714 就是一种解法,
5+3/1+972/486 是另一种解法。
这个算式一共有多少种解法?
答案
29
解题过程
用A[9]存储1~9,用B[i]表示A~I(下标i从0~8分别代表A~I的值),用dfs每次更替B[i]中的值,在通过is_true()判断算式是否成立。
附上代码
#include<iostream>
using namespace std;
int a[9]={1,2,3,4,5,6,7,8,9};//代表A~I
int b[9]={0};//存储每次A~I所代表的值,其中
int vis[9]={0};//0-没访问
int counts=0;
int main()
{
void dfs(int);
dfs(0);
cout<<counts<<endl;
return 0;
}
bool is_true()
{
int GHI=b[6]*100+b[7]*10+b[8];
int DEF=b[3]*100+b[4]*10+b[5];
if(b[0]*b[2]*GHI+b[1]*GHI+b[2]*DEF==b[2]*GHI*10)
return true;
return false;
}
void dfs(int index)
{
if(index==9)
{
if(is_true())
counts++;
return;
}
for(int i=0;i<9;i++)
{
if(vis[i]==0)
{
vis[i]=1;
b[index]=a[i];
dfs(index+1);
vis[i]=0;
}
}
}
边栏推荐
- Advanced multithreading: the role and implementation principle of volatile
- 基于Easy CHM和VS的帮助文档制作
- Review of metallurgical physical chemistry ---- gas solid reaction kinetics
- ArrayList multithreading security solution
- DOM——页面的渲染、style属性操作、预加载与懒加载、防抖与节流
- Review of metallurgical physical chemistry -- Fundamentals of metallurgical reaction kinetics and characteristics of multiphase reaction kinetics
- Openjudge: stone scissors cloth
- SVG了解与绘图应用
- Implementation of date class and its basic functions
- 树莓派蓝牙调试过程
猜你喜欢

冶金物理化学复习 --- 液 - 液相反应动力学

Event_looop-事件循环机制

Delete specific elements in order table OJ

冶金物理化学复习 --- 金属的电沉积,还原过程

You must configure either the server or JDBC driver (via the ‘serverTimezone)

冶金物理化学复习 ---- 气固反应动力学

DOM基础

Thesis writing function words

Microsoft Edge浏览器插件(2)

Advanced multithreading: the role and implementation principle of volatile
随机推荐
日期类及其基本功能的实现
NPM, YRAN, NPX的差异与关系
Advanced multi threading: the underlying principle of synchronized, the process of lock optimization and lock upgrade
How Visio can quickly generate the same pattern and image matrix
分支与循环语句
URL form
openjudge:字符串最大跨距
Canvas绘图1
ArcGIS之Model Builder
Using Navicat or PLSQL to export CSV format, more than 15 digits will become 000 (e+19) later
Interface idempotency problem
冶金物理化学复习 ---- 气固反应动力学
Review of metallurgical physical chemistry ---- gas solid reaction kinetics
curd组件中的时间设置
树莓派WIFI一键连接配置
ArcMap中的距离工具条(Distance)
media-搭建直播服务器
Advanced multithreading: Lock strategy
openjudge:过滤多余的空格
截图传入后台