Files
python/TangDou/LianXiTi50/43.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

30 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
/*
题目:求0—7所能组成的奇数个数。 (不可重复 0不能做首位) 46972
思路: 0-7不能重复 统计1位,2位,3位, 4位, 5位, 6位,7位,8位,每个位数的奇数个数
1位 4 (1,3,5,7)
2位 6*4 =4*6 最后一位是4种,那么首位就是除了0,再有就是不能和末位一样,就是8-2=6个,乘法原理:6*4=24个
3位 6*6*4 =4*6*6 首位末位参加2位时情况,中间位可以是不可以与首、末位重复的数字,也是6种
4位 6*6*5*4 =4*6*6*5 其余项参考3位情况,多出的一位可选择数量为5
5位 6*6*5*4*4 =4*6*6*5*4 其余项参考4位情况,多出的一位可选择数量为4
6位 6*6*5*4*4*3 =4*6*6*5*4*3
7位 6*6*5*4*4*3*2 = 4*6*6*5*3*2
8位:6*6*5*4*4*3*2*1 =4*6*6*5*4*3*2*1
*/
int main() {
//加一位和两位的个数
int cnt = 4 + 4 * 6;
int x = 6;
//从3到8
for (int i = 3; i <= 8; i++) {
cnt += 6 * 4 * x;
x = x * (8 - i);
}
printf("%d\n", cnt);
return 0;
}