Problem Statement
There are some cities and some roads connecting them together. The road network has the topology of a perfect binary tree (see below for a picture), in which the cities are nodes and the roads are edges.
You are given the
The picture below shows how the road network looks like when treeHeight = 2.
We want to send some cars into the road network. Each car will be traveling from its starting city to its destination city without visiting the same city twice. (Note that the route of each car is uniquely determined by its starting and its destination city.) It is possible for the starting city to be equal to the destination city, in that case the car only visits that single city.
Our goal is to send out the cars in such a way that each city will be visited by exactly one car. Let X be the smallest number of cars we need in order to do so. Compute and return the value X modulo 1,000,000,007.
Definition
- Class:
- TrafficCongestion
- Method:
- theMinCars
- Parameters:
- int
- Returns:
- int
- Method signature:
- int theMinCars(int treeHeight)
- (be sure your method is public)
Constraints
- treeHeight will be between 0 and 1,000,000, inclusive.
Examples
1
Returns: 1
In this case, one car can visit all the cities.
2
Returns: 3
Here is one way to visit all cities exactly once by three cars:
3
Returns: 5
585858
Returns: 548973404
0
Returns: 1
4
Returns: 11
5
Returns: 21
6
Returns: 43
7
Returns: 85
8
Returns: 171
9
Returns: 341
10
Returns: 683
11
Returns: 1365
12
Returns: 2731
13
Returns: 5461
14
Returns: 10923
15
Returns: 21845
16
Returns: 43691
17
Returns: 87381
18
Returns: 174763
19
Returns: 349525
20
Returns: 699051
25
Returns: 22369621
30
Returns: 715827883
35
Returns: 906492091
40
Returns: 7746720
45
Returns: 247895029
50
Returns: 932640890
55
Returns: 844508266
60
Returns: 24264334
70
Returns: 846677507
80
Returns: 997760765
90
Returns: 707015872
100
Returns: 984247526
200
Returns: 999630053
300
Returns: 548033842
500
Returns: 260322005
700
Returns: 120478547
1000
Returns: 458948807
3000
Returns: 443800320
5000
Returns: 573461717
10000
Returns: 270407868
30000
Returns: 777260071
50000
Returns: 12110301
100000
Returns: 71815678
500000
Returns: 311754146
1000000
Returns: 490028042
999999
Returns: 745014024
679379
Returns: 19761069
191807
Returns: 565569761
590524
Returns: 789815123
730706
Returns: 862680469
606763
Returns: 438659788
531434
Returns: 322697396
206743
Returns: 548124278
260716
Returns: 134950712
80188
Returns: 302907143
309019
Returns: 305102876
850657
Returns: 419343001
10464
Returns: 874709788
577394
Returns: 187290663
756092
Returns: 954114375
460375
Returns: 30653388
25693
Returns: 520134322
855602
Returns: 263216797
454356
Returns: 756144638
53077
Returns: 235894722
110324
Returns: 46881352
388295
Returns: 520690119
347315
Returns: 909029981
514547
Returns: 893500017
101646
Returns: 704924855
372640
Returns: 298024908
627719
Returns: 484506965
257690
Returns: 257076174
79948
Returns: 7888535
30915
Returns: 32206084
265009
Returns: 378700405
747474
Returns: 822915066