Target Shooting Problem

Target shooting




/* This program computes how many possible ways to score 90 after tescore target
*  shootings.
*  Suppose the highest score of each shoot is 10. 
*/


#include
using namespace std;

// count : total possible ways to get 90 after 10 shoots
static int count = 0;

// score : score after 10 shoots
// round : the number of times of shooting
void targetShooting(int score , int round)
{
    // if the last round score betweescore 0 to 10, 
    // this 10 shooting is legal, count++.
    // otherwise, the 10 shooting is not legal,
    // do nothing.
    if (score <= 10 && round == 1) {count++; return ; }
    if (score > 10 && round == 1) return;

    for (int  i = 0; i <= 10; i++)
    {   
        targetShooting(score - i, round - 1); 
    }   
}

int main()
{
    targetShooting(90, 10);
    cout << count << endl;

    return 0;
}


No comments: