fork download
  1. #include <stdio.h>
  2.  
  3. int maina(int n)
  4. {
  5. int count[100][10];
  6. int i, j;
  7.  
  8. count[0][0] = 0;
  9. for (i = 1; i <= 9; i++)
  10. count[0][i] = 1;
  11.  
  12. for (i = 1; i < n; i++)
  13. {
  14. count[i][0] = count[i - 1][1];
  15. for (j = 1; j < 9; j++)
  16. {
  17. count[i][j] = count[i - 1][j - 1] + count[i - 1][j + 1];
  18. count[i][j] = count[i][j] % 1000000000;
  19. }
  20. count[i][9] = count[i - 1][8];
  21. }
  22.  
  23. int sum = 0;
  24. for (i = 0; i < 10; i++)
  25. {
  26. sum += count[n - 1][i];
  27. sum = sum % 1000000000;
  28. }
  29. return sum;
  30. }
  31.  
  32. int main()
  33. {
  34. for (int i = 1; i <= 100; i++)
  35. printf("%d: %d\n", i, maina(i));
  36. }
Success #stdin #stdout 0s 5520KB
stdin
4
stdout
1: 9
2: 17
3: 32
4: 61
5: 116
6: 222
7: 424
8: 813
9: 1556
10: 2986
11: 5721
12: 10982
13: 21053
14: 40416
15: 77505
16: 148785
17: 285380
18: 547810
19: 1050876
20: 2017126
21: 3869845
22: 7427671
23: 14250855
24: 27351502
25: 52479500
26: 100719775
27: 193258375
28: 370895324
29: 711682501
30: 365808847
31: 620797529
32: 29557817
33: 651169213
34: 521263854
35: 540683515
36: 204355370
37: 879348046
38: 162096632
39: 965636015
40: 903595810
41: 846161206
42: 956694551
43: 895740532
44: 438883703
45: 516874370
46: 561265139
47: 581584465
48: 855111334
49: 385914370
50: 894685264
51: 689520486
52: 126768895
53: 898163271
54: 38535971
55: 77006176
56: 845874048
57: 470569921
58: 405602943
59: 557777926
60: 307863967
61: 756331127
62: 568214309
63: 402216081
64: 40265961
65: 983357944
66: 989461745
67: 163661704
68: 452853050
69: 229306760
70: 564706557
71: 621851080
72: 997859582
73: 556077001
74: 217149178
75: 147031753
76: 975669796
77: 241977853
78: 608191245
79: 425147188
80: 352000974
81: 477752228
82: 27718678
83: 215474349
84: 262236643
85: 959722295
86: 756842014
87: 190316896
88: 767282487
89: 641093787
90: 828469300
91: 276888313
92: 555953587
93: 22100065
94: 570935361
95: 989279221
96: 815748022
97: 549712215
98: 154160622
99: 508863114
100: 18404112