当前位置:网站首页>结果填空 奖券数目(dfs * 数学公式)
结果填空 奖券数目(dfs * 数学公式)
2022-07-28 05:19:00 【小白鼠零号】
有些人很迷信数字,比如带“4”的数字,认为和“死”谐音,就觉得不吉利。
虽然这些说法纯属无稽之谈,但有时还要迎合大众的需求。某抽奖活动的奖券号码是5位数(10000-99999),要求其中不要出现带“4”的号码,主办单位请你计算一下,如果任何两张奖券不重号,最多可发出奖券多少张。
请提交该数字(一个整数),不要写任何多余的内容或说明性文字。
答案
52488
解题过程
这题我将它看成是一个dfs(深搜)的过程,深搜要明确初始条件和结束条件。初始条件:0~9(除掉4)这9个数。终止条件:五位数都选好了时候就退出该次深搜。
注意:五位数中,万位的数不能是0,只能是1~9(去掉4)这8个数。
数学算法:8*9*9*9*9 ,表示:第一位有8个数可选,第二、三、四、五位都可以有9位数选择。
附上代码
#include<iostream>
using namespace std;
int a[9]={0,1,2,3,5,6,7,8,9};
int counts=0;
int main()
{
void DFS(int);
DFS(0);
cout<<counts<<endl;
return 0;
}
void DFS(int index)
{
if(index==5)
{
counts++;
return;
}
for(int i=0;i<9;i++)
{
if(index==0&&i==0)//万位不能是0
continue;
DFS(index+1);
}
}
边栏推荐
- The difference between get and post
- es6新增数据类型--->Symbol、Map、Set
- [idea plug-in artifact] teaches you how to set all attributes in an entity class with one click of idea
- Shell operation principle
- Deep learning medical image model reproduction
- Oracle view lock table statement and unlocking method
- 环形链表问题
- Review of metallurgical physical chemistry -- Fundamentals of chemical reaction kinetics
- c语言:通过一个例子来认识函数栈帧的创建和销毁讲解
- 基于Easy CHM和VS的帮助文档制作
猜你喜欢

ArcMap中的距离工具条(Distance)

顺序表oj之删除特定的元素

Custom JSON return data

VMware Workstation is incompatible with device/credential guard. Disable device/credential guard

Review of metallurgical physical chemistry --- liquid liquid reaction kinetics

Idea configures the service (run dashboard) service, and multiple modules are started at the same time

Leetcode 随即链表的深拷贝

Review of metallurgical physical chemistry -- Fundamentals of metallurgical reaction kinetics and characteristics of multiphase reaction kinetics

冶金物理化学复习 -- 金属电沉积过程中的阴极极化,超电势以及阳极和阳极过程

c语言:通过一个例子来认识函数栈帧的创建和销毁讲解
随机推荐
Centos7 install MySQL 5.7
【面试题】防抖和节流
VMware Workstation is incompatible with device/credential guard. Disable device/credential guard
Arcgis Engine安装的若干问题
Pytorch uses hook to get feature map
Deep learning medical image model reproduction
冶金物理化学复习 --- 液 - 液相反应动力学
JS数组的方法大全
三大缓存技术--localStorage、sessionStorage、Cookie
Interface idempotency problem
Mabtis (I) basic use of framework
uniapp-监听app是否有网络连接
media-搭建直播服务器
curd组件中的时间设置
设置滚动条
GD32F407 移植FreeRTOS+Lwip
Openjudge: find the first character that appears only once
Collection of architectural design considerations
Mutual conversion between latex and word
树莓派蓝牙调试过程