当前位置:网站首页>结果填空 奖券数目(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);
}
}
边栏推荐
- Merge two ordered arrays of order table OJ
- Openjudge: stone scissors cloth
- [idea plug-in artifact] teaches you how to set all attributes in an entity class with one click of idea
- ES6----解构赋值
- Openjudge: find all substring positions
- Openjudge: judge whether the string is palindrome
- 链表中关于快慢指针的oj题
- Docker deploy mysql5.7.35
- 顺序表oj之删除特定的元素
- DOM--事件链、事件冒泡和捕获、事件代理
猜你喜欢

顺序表oj题目

ArcMap地图投影相关操作

冶金物理化学复习 --- 化学反应动力学基础

树莓派串口配置

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

Canvas绘图2

Review of metallurgical physical chemistry -- cathodic polarization, overpotential, anode and anode process in metal electrodeposition

函数基础知识以及特殊点

Merge two ordered arrays of order table OJ

Mutual conversion between latex and word
随机推荐
Advanced multithreading: the role and implementation principle of volatile
Canvas绘图1
VMware Workstation is incompatible with device/credential guard. Disable device/credential guard
树莓派串口配置
uni-app-双击事件模拟
Oracle uses SQL to query the field information of a table (field type, length, etc.)
在线词云图生成(以WordArt为例)
链表中关于快慢指针的oj题
Zotero——一款文献管理工具
Microsoft Edge浏览器插件(1)
全局事件总线
Openjudge: perpetual calendar
[MySQL] solve the problem of MySQL time zone and 8-hour difference in database time
Mutual conversion between latex and word
日期类及其基本功能的实现
shell运行原理
openjudge:判断字符串是否为回文
Using Navicat or PLSQL to export CSV format, more than 15 digits will become 000 (e+19) later
基于Easy CHM和VS的帮助文档制作
Simpledateformat thread unsafe and datetimeformatter thread safe