- URL
- 题目
- 分析
- 源码
- 工程结构
- 源码文件
- LOG参考
- 源码概述
- 小结
链接:https://leetcode-cn.com/problems/count-numbers-with-unique-digits/
题目
分析
源码 工程结构
.
└── main_357.c
源码文件
/* main_357.c */
#include
int count_num_with_unique_digits(int n){
if (n == 0)
return 1;
if (n == 1)
return 10;
int ans = 10 , cur = 9;
for (int i = 0; i < n - 1; i++){
cur *= 9 - i;
ans += cur;
}
return ans;
}
int main()
{
for (int i = 0 ; i <= 10; ++i){
printf("n = %d , \t count = %d\n",i,count_num_with_unique_digits(i));
}
return 0;
}
LOG参考
n = 0 , count = 1
n = 1 , count = 10
n = 2 , count = 91
n = 3 , count = 739
n = 4 , count = 5275
n = 5 , count = 32491
n = 6 , count = 168571
n = 7 , count = 712891
n = 8 , count = 2345851
n = 9 , count = 5611771
n = 10 , count = 8877691
源码概述
- C1/9 * C1/(9-1) *…*C1/(9-(n-1)),n∈[2,10]
- 一个累乘的结果
小结
- 算法来源于生活
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)