An old question:
How many types of attacks can a Shooting athlete send with 10 shots and 90 rings? Use a program to print out each type. (Each score is an integer between 0 and 10 rings. The score can be set to 0 or 10 rings ).
Idea: Use recursive thinking
First, take into account that a total of ten shots are required. You can consider the following three situations:
1. If you have exceeded ten guns or the points have exceeded the given value, the system returns
2. If the current number is 10, determine whether the points of the last gun may reach the given value (0 ~ 10)
If possible, add 1 to the value and then return; otherwise, return directly.
3. Continue recursion in other cases
Source code:
# Include <iostream> <br/> using namespace STD; </P> <p> int sum = 0; <br/> int score = 90; </P> <p> void compute (INT num, int scores) <br/>{< br/> If (Num <= 0 | scores> score) return; </P> <p> If (num = 1) <br/> {<br/> If (scores + 10> = score) sum ++; <br/> return; <br/>}< br/> for (INT I = 0; I <= 10; + I) <br/> {compute (num-1, scores + I) ;}< br/>}</P> <p> int main () <br/>{< br/> compute (10, 0 ); <br/> cout <sum <Endl; <br/> return 0; <br/>}