打靶问题 一个射击运动员打靶,靶一共有10环,连开10枪打中90环的可能行有多少种?

#include "Shot.h" Shot::Shot(void) { } Shot::~Shot(void) { } int Shot::ShotNum(int Nshot, int Ncounter) { int sum = 0; //最终结果 if (Nshot == 0) //没开枪 return 0; if (Nshot == 1) //只开一枪 return 1; if (Ncounter < 0 || Ncounter > 10 * Nshot) //环数超出范围 return 0; //此处不知该如何处理、保留 Nshot--; for(int i = 0; i <= 10;i++) { int tmpcounter = Ncounter - i; if (tmpcounter >=0) //环数未超出范围的情况下 sum += ShotNum(Nshot,tmpcounter); //迭代,将每种情况全部加起来 } return sum; } int main() { int n,k; Shot* s; while(1) { std::cout << "输入枪数和环数:" << std::endl; std::cin >> n >> k; int m = 0; m = s->ShotNum(n,k); std::cout << "可能的方式数目为:"<< m << std::endl; } _getch(); }

你可能感兴趣的:(include)