z-mario
Little Z. has found his old GameBoy. One of his favorite games used to be Super Zario. The game is based on the Super Mario game, but has some different rules. You are starting from Level 1, each level is shown on the map. After completing that level, you have a choice to go to different levels. For example, after completing Level 1, you can play Level 1 again, or Level 2, or Level 5, etc.., that means that on the map of the levels there is an one way path between level 1 and: level1, level2, level5, etc..
Mister Little Z always completes the level, he is so good at the game that he never dies. So he came up with the following questions. "In how many ways you can end-up at each of the levels, if you have successfully completed exactly K levels". Assuming you are starting from Level 1
3 3 20000
1 2
2 3
3 1Output:
0
0
1Explanation: After completing each level you can only take one path, therefore, after completing 20000 levels you must end-up at level 3 (i.e. you are completing levels: 1, 2, 3, 1, 2, 3, 1, 2, 3...)
2 3 3
1 1
1 2
1 1Output:
8
4Explanation: In this case we have to ways of going from level 1 back to level 1. So in three steps we can end up in level one in 2*2*2 ways. In order to end-up in level 2 we have to have the last step being going from level 1 to level 2, so we can go from level 1 to level 1 in 2*2 ways (in 2 steps), and then take the final step to level 2.
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.