打靶问题

nulang 2009-01-28 09:42:07
一个射击运动员打靶,靶一共有10环,连开10枪打中90环的可能性有多少种?请用递归算法编程实现?大家谁会做吗
...全文
238 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
waizqfor 2009-01-28
  • 打赏
  • 举报
回复
老问题了

#include <stdio.h>

int store[10];
int sum;
int main()
{
shoot(90,10);
printf("It has %d compound",sum);
}

shoot(int socre,int num)
{
int i;
if(socre<0||socre>num*10)
return;
if(num==1)
{
store[10-num]=socre;
prints();
return;
}
for(i=0;i<=10;i++)
{
store[10-num]=i;
shoot(socre-i,num-1);
}
}

int prints()
{
int i;
for(i=0;i<10;i++)
{
printf("%d",store[i]);
}
sum++;
printf("\n");
}
Crob 2009-01-28
  • 打赏
  • 举报
回复
穷举法,花不了多少时间。
大过年的,穷举吧。

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧