PAT-10道题

PAT算法刷题

1002

clike 复制代码
一:对于每一的1到6都进行枚举,进行递归操作
二:如果位数到了指定的n的时候,递归的条件,进行判断是否可以整除操作
#include<iostream>
#include<algorithm>
using namespace std;
long long n, k, ans;
void dfs(int times, int sum)
{
	if (times == n)
	{
		if (sum % n == 0)
		{
			ans++;
		}
		return;
	}
	int i;
	for (int i = 1; i <= 6; i++)
	{
		dfs(times + 1, sum * 10 + i);
	}
}
int main()
{
	cin >> n >> k;
	dfs(0, 0);
	cout << ans;
	return 0;
}
相关推荐
L_cl3 小时前
【Python 算法零基础 1.线性枚举】
python·算法
阿饼2404 小时前
算法——图论——交通枢纽
c++·算法·动态规划·图论
its_a_win4 小时前
洛谷 P1182 数列分段 Section II 二分详细讲解
c++·算法
奋进的小暄6 小时前
贪心算法(7)(java) 分发饼干
数据结构·算法·贪心算法
大模型铲屎官6 小时前
从零精通机器学习:线性回归入门
开发语言·人工智能·python·算法·机器学习·回归·线性回归
试剂界的爱马仕6 小时前
投资早报 3.14
人工智能·深度学习·算法·机器学习·区块链·ai写作
ksbglllllll6 小时前
ccf3401矩阵重塑(其一)
c++·算法·矩阵
king-xxz6 小时前
力扣No.673.最长递增子序列的个数
数据结构·算法·leetcode
飞奔的马里奥7 小时前
力扣Hot100——169. 多数元素
java·算法·leetcode
一只_程序媛7 小时前
【leetcode hot 100 105】从前序与中序遍历序列构造二叉树
算法·leetcode·职场和发展