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: Accepted)

use std::collections::HashSet;
use std::cmp::max;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// fn main() {
//     input! {
//         S: chars,
//         T: chars,
//         n: i32,
//         m: i32,
//         U: chars
//     }
//     if S == U {
//         println!("{} {}", n-1, m);
//     } else {
//         println!("{} {}", n, m-1);
//     }
// }

/*
fn main() {
    input! {
        S: chars
    }
    let L = S.len();
    for i in 0..L {
        print!("x");
    }
    println!();
}*/

/*
fn main() {
    input! {
        N: usize,
        A: [i64; N],
    }
    let mut H = HashSet::new();
    for a in &A {
        H.insert(a);
    }
    if H.len() == A.len() {
        println!("YES");
    } else {
        println!("NO");
    }
}*/

/*
fn main() {
    input! {
        N: usize,
        K: usize,
        P: [f64; N]
    }
    let mut tmp = 0.0;
    for i in 0..K {
        tmp += (P[i]+1.0)/2.0;
    }
    let mut ans = tmp;
    for i in K..N {
        tmp += (P[i]+1.0)/2.0 - (P[i-K]+1.0)/2.0;
        if ans < tmp {
            ans = tmp;
        }
    }
    println!("{}", ans);
}*/

fn main() {
    input! {
        N : chars,
        K : usize
    }
    let L = N.len();
    let mut dp = vec![vec![vec![0; 2]; K+2]; L+1];
    dp[0][0][0] = 1;
    for i in 0..L {
        let num = N[i] as i32 - 48;
        //println!("{}", num);
        for k in 0..(K+1) {
            for n in 0..10 {
                for isless in 0..2 {
                    if n != 0 {
                        if isless == 1 || n == num {
                            dp[i+1][k+1][isless] += dp[i][k][isless];
                        } else if n < num {
                            dp[i+1][k+1][1] += dp[i][k][isless];
                        }
                    } else {
                        if isless == 1 || n == num {
                            dp[i+1][k][isless] += dp[i][k][isless];
                        } else if n < num {
                            dp[i+1][k][1] += dp[i][k][isless];
                        }
                    }
                }
            }
            //println!("{} {} {}", k, dp[i+1][k][0], dp[i+1][k][1]);
        }
    }
    
    println!("{}", dp[L][K][1] + dp[L][K][0]);
}