1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
typedef long long ll;
// d[n][k] k로 시작하는 n자리 증가하는 수
ll d[82][10];
int n;
 
int strlen(char* c) {
    int i = 1;
    for (; c[i]; i++) {
        if (c[i] < c[i - 1]) return -1;
    }
    return i;
}
 
int main() {
    for (int i = 1; i < 10; i++) d[1][i] = 1;
    for (int i = 2; i < 82; i++)
        for (int j = 1; j < 10; j++)
            for (int k = j; k < 10; k++)
                d[i][j] += d[i - 1][k];
 
    scanf("%d"&n);
    while (n--) {
        char s[82];
        scanf("%s"&s);
        ll res = 0;
        int l = strlen(s);
        if (l == -1printf("-1\n");
        else {
            for (int i = 0; i < l; i++) {
                if (s[i] == '9') {
                    res += d[l + 1-i][1];
                }
                else res += d[l + 1 - i][1- d[l + 1 - i][s[i] - '0' + 1];
            }
            printf("%lld\n", res);
        }
    }
    return 0;
}
 
cs


'BOJ' 카테고리의 다른 글

2257 화학식량  (0) 2018.04.04
14617 제 3회 IUPC  (0) 2018.03.09
11585 속타는 저녁 메뉴  (0) 2018.02.18
4354 문자열 제곱  (0) 2018.02.18
1305 광고  (0) 2018.02.18

+ Recent posts