Problem Statement
Fox Ciel is going to walk along an unpaved road to her friend's house. For our purposes, the road can be considered a one-dimensional polyline consisting of N segments. The segments are numbered 0 through N-1 along the road. At the beginning, Ciel stands on the segment number 0. Her friend's house is on the segment number N-1.
Unfortunately, yesterday it rained, so some segments of the road are now muddy. Ciel has new shoes, so she must only use the other, dry segments. She knows that segments 0 and N-1 are dry. The friend just called her and gave her two additional pieces of information:
- Out of the remaining N-2 segments, exactly muddyCount are muddy.
- There is an even number of ways how Ciel can get to the friend's house without stepping into the mud, while making steps of length at most 2.
We will now explain the second information in more detail. When Ciel walks along the road, each of her steps has either length 1 or 2. A step of length 1 takes her from segment i to segment i+1. A step of length 2 takes her from segment i to segment i+2, skipping the (possibly, but not necessarily muddy) segment i+1.
Fox Ciel would like to use the information she has to determine how the road looks like. Of course, there may be multiple configurations that match the information. It is also possible that her friend was mistaken and there is no sequence of dry and muddy segments that matches what she told Ciel.
You are given the
Definition
- Class:
- MuddyRoad2
- Method:
- theCount
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int theCount(int N, int muddyCount)
- (be sure your method is public)
Notes
- Zero (0) is also an even number. Hence, if Ciel cannot reach her friend's house without stepping into the mud, there is an even number of ways to reach the house.
- Two configurations of the road are different if some road segment is dry in one of them and muddy in the other.
Constraints
- N will be between 2 and 555, inclusive.
- muddyCount will be between 0 and N-2, inclusive.
Examples
5
1
Returns: 2
There are two possible configurations of the road: .#... and ...#. (where '#' denotes a muddy segment and '.' a dry one).
5
2
Returns: 2
Possible configurations: .##.. and ..##. Note that in these configurations, there are no ways to go from part 0 to part 4 without stepping onto any muddy parts. You have to count this kind of configurations too, since 0 is an even number.
10
4
Returns: 65
314
78
Returns: 498142902
555
222
Returns: 541606281
2
0
Returns: 0
3
0
Returns: 1
3
1
Returns: 0
4
0
Returns: 0
4
1
Returns: 0
4
2
Returns: 1
5
0
Returns: 0
5
3
Returns: 1
555
0
Returns: 1
555
1
Returns: 368
555
2
Returns: 101568
555
553
Returns: 1
555
552
Returns: 553
555
551
Returns: 152628
551
44
Returns: 370263114
550
32
Returns: 191831629
552
408
Returns: 367514370
550
155
Returns: 206394093
552
490
Returns: 79384035
550
100
Returns: 214249245
553
449
Returns: 189651465
552
28
Returns: 388963015
555
79
Returns: 275324190
555
497
Returns: 121006185
551
300
Returns: 433110435
553
481
Returns: 148498515
552
404
Returns: 469165365
554
145
Returns: 260141345
553
155
Returns: 438163677
555
130
Returns: 263039908
555
248
Returns: 257269323
551
133
Returns: 97420847
552
504
Returns: 258794445
555
179
Returns: 398531700
185
45
Returns: 76442085
263
85
Returns: 496249136
11
0
Returns: 0
431
426
Returns: 13067054
313
18
Returns: 449909475
389
179
Returns: 96532467
190
104
Returns: 182989420
420
103
Returns: 476477145
210
73
Returns: 376235647
427
273
Returns: 228160755
202
137
Returns: 267944565
165
59
Returns: 40455450
190
65
Returns: 202196919
26
15
Returns: 1307504
536
374
Returns: 216998280
89
19
Returns: 236601030
438
311
Returns: 488030553
123
96
Returns: 472504689
500
4
Returns: 522246270
468
2
Returns: 72075
551
537
Returns: 33869106
254
216
Returns: 55183095
58
6
Returns: 30867648
293
207
Returns: 201267795
481
8
Returns: 553652025
16
3
Returns: 304
307
32
Returns: 205435426
165
124
Returns: 168511185
451
17
Returns: 534049564
360
203
Returns: 222879393