/* This program computes how many possible ways to score 90 after tescore target * shootings. * Suppose the highest score of each shoot is 10. */ #includeusing 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; }
Target Shooting Problem
Posted at
7/08/2011 02:44:00 PM
Target shooting
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment