返回题解分享
讨论 / 题解分享/ 帖子详情

凑算式(结果填空) - 题解

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
vector<int> path;
int used[10];
int res;
void dfs(int count){
	if(count>9){
		int x = path[4] * 100 + path[5] * 10 + path[6];
		int y = path[7] * 100 + path[8] * 10 + path[9];
// 判断是否满足条件
		if (path[1] * path[3] * y + path[2] * y + x * path[3] == 10* path[3] * y){
		res++; // 满足条件的排列数量加一
		return;
}
	}
//	处理单层递归的逻辑
	for(int i=1;i<=9;i++){
		if(used[i]) continue;
		path.push_back(i);
		used[i]=1;
		dfs(count+1);
		used[i]=0;
		path.pop_back();
	}
}
int main(){
	path.push_back(0);
	dfs(1);
	cout<<res;
	return 0;
}
0 回复 0 转发 0 喜欢 2 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!