Problem:
Score : 500 points

Problem Statement

Find the number of integers between 1 and N (inclusive) that contains exactly K non-zero digits when written in base ten.

Constraints

1 \leq N < 10^{100}

1 \leq K \leq 3

Input

Input is given from Standard Input in the following format:

N
K

Output

Print the count.

Sample Input 1

100
1

Sample Output 1

19

The following 19 integers satisfy the condition:

1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100

Sample Input 2

25
2

Sample Output 2

14

The following 14 integers satisfy the condition:

11,12,13,14,15,16,17,18,19,21,22,23,24,25

Sample Input 3

314159
2

Sample Output 3

937

Sample Input 4

9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
3

Sample Output 4

117879300

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

use std::io;
use std::str::FromStr;

fn input_char_vec() -> Vec<char> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().chars().collect()
}

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn combination(n: u64, mut m: u64) -> u64 {
    if n < m {
        return 0;
    }
    if m > n - m {
        m = n - m
    }

    let mut ret = 1u64;
    for i in 0..m {
        ret *= n - i;        
    }

    let mut div = 1u64;
    for i in 1..(m+1) {
        div *= i;
    }
    ret / div
}

fn recur(idx: usize, n: &Vec<char>, left: u64) -> u64 {
    if idx == n.len() {
        return 1;
    }
    if left == 0 {
        return 1;
    }
    let d: u64 = n[idx] as u64 - 48;
    let mut tmp = recur(idx+1, n, left-1); // 現在の桁と同じ値をとった場合
    tmp += combination((n.len() - idx - 1) as u64, left - 1) * 9u64.pow(left as u32 - 1) * (d - 1); // 現在の値より小さな値をとった場合
    if left as usize != n.len() - idx {
        // 採用しなかった場合
        if d != 0 {
            tmp += combination((n.len() - idx - 1) as u64, left) * 9u64.pow(left as u32); 
        } else {
            tmp += recur(idx+1, n, left);
        } 
    } 
    tmp
}

fn main() {
    let n = input_char_vec();
    let k: usize = input();

    let d = n.len();
    if k > d {
        println!("0");
        return;
    }
    println!("{}", recur(0, &n, k as u64));
}