Testing of Job-hopping Programs for Programmers in Yahoo! JAPAN

  ios, question

A rescue robot has three jumping modes, which can jump distances of 1m, 2m and 3m respectively. Please use the program to realize the available jumping modes when the robot travels n meters.
The program language is not limited. When the distance n is large enough, the execution time of the program is as small as possible.

For example, when the distance is 4 meters, there are 7 kinds of output results:

1m,1m,1m,1m
 1m,1m,2m
 1m,2m,1m
 1m,3m
 2m,1m,1m
 2m,2m
 3m,1m

Thank you for inviting me.

This problem is obviously designed to examine your DP. I also don’t say much, directly put yards to come over:

cppvoid step(int n, std::string str) {
 if (n == 0) { std::cout << str << "\b " << std::endl;  bracket
 If (n >= 1) step(n-1, str plus "1m,");
 If (n >= 2) step(n-2, str plus "2m,");
 If (n >= 3) step(n-3, str plus "3m,");
 bracket

Whenn == 4When, call:step(4, "");Output what you want as is.


Here is only the shortest code to express my thoughts, afraid of breaking the stack, to modify.