啊哈,算法!-----dfs2
来源:互联网 发布:手机号定位软件 编辑:程序博客网 时间:2024/04/29 07:57
从1~9九个组成形如abc+def=ghi的式子
输出式子的总数
代码实现
#include<iostream>#include<cstdio>using namespace std;int a[10],book[10],total=0;void dfs(int step){ int i; if(step==10) { if(a[1]*100+a[2]*10+a[3]+ a[4]*100+a[5]*10+a[6]== a[7]*100+a[8]*10+a[9] ) //符合if语句,即题意的式子 { total--; printf("%d%d%d+ %d%d%d =%d%d%d\n", a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9]); return ; } } for(i=1;i<=9;i++) { if(book[i]==0) { a[step]=i; book[i]=1; dfs(step+1);//递归调用 book[i]=0; } } return ;}int main(){ dfs(1); printf("total=%d",total/2);//739+ 125和125+739是一种情况除以2 return 0;}
0 0
- 啊哈,算法!-----dfs2
- 《啊哈!算法》
- 《啊哈!算法》
- 啊哈!算法
- 啊哈!算法-------算法类书籍
- 《啊哈!算法》.啊哈磊.扫描版pdf
- 二. 啊哈,算法!
- 第二章 啊哈!算法
- 编程珠玑 ~~ 啊哈! 算法
- (2)啊哈!算法
- 啊哈算法-----快速排序
- 啊哈算法 之 队列
- 啊哈,算法! -----dfs1
- 啊哈,算法!-----dfs3
- 啊哈磊的算法
- 《啊哈算法》第一章 排序
- 啊哈!算法—小哼买书
- 啊哈!算法—队列
- [leetcode-76]Minimum Window Substring(java)
- mongoDB add user in v3.0 问题的解决(Property 'addUser' of object admin is not a func)
- win7 驱动程序安装 如何跳过 windows update
- poj 2251 Dungeon Master(优先队列bfs)
- Making Applications Accessible
- 啊哈,算法!-----dfs2
- 【JAVA语言基础】map以value进行排序
- func_get_arg,func_get_args,func_num_args实现PHP伪重载
- 【华为oj】句子逆序
- hdoj2553N皇后问题【DFS】
- POJ 1873 The Fortified Forest(凸包+枚举 World Finals 1999啊)
- 黑马程序员-面向对象基础知识1
- HR-资产管理
- JavaScript基础----03Javascript基础-变量和数据类型