递归实现打靶问题
来源:互联网 发布:蓝鸥unity3d培训多少钱 编辑:程序博客网 时间:2024/05/01 05:30
一个射击运动员打靶,靶一共有10环,连开10枪打中N环的可能行有多少种?
代码如下:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
static int num = 0;
static int score[10];
void output()
{
int total = 0;
for (int i = 0; i < 10; i ++)
{
cout << score[i]<<" ";
total += score[i];
}
cout<<"total:"<<total<<endl;
}
void compute(int left_score, int left_shot)
{
if (left_score < 0 || left_score > left_shot *10)
//打靶总分数超出了或以后及时每次打10环都不够
return;
if (left_shot == 1)
//最后一枪
{
score[0] = left_score;
++ num;
output();
return;
}
for (int i = 0; i <= 10; i ++)
{
score[left_shot - 1] = i;
compute(left_score - i, left_shot - 1);
}
}
int main()
{
compute(2,10);
cout<< num<<endl;
return 1;
}
- 递归实现打靶问题
- 打靶问题(递归)
- 打靶(递归)问题
- 打靶问题的程序实现
- 递归 打靶
- 打靶问题的一种递归解法
- 打靶问题
- 打靶问题
- 打靶问题
- 打靶问题
- 打靶问题
- 打靶问题
- 打靶问题
- Python解决打靶问题
- 运动员打靶问题
- 【算法】打靶问题求解
- 运动员打靶问题
- 打靶
- [小e笔记]之一步一步学习备份恢复——第三篇 数据库恢复案例(Part 5)
- 项目开始尽可能定义
- 《清平乐词》三篇——李白
- ubuntu 安装qq2012
- ios5 中文键盘高度变高覆盖现有ui问题的解决方案(获取键盘高度的方法)
- 递归实现打靶问题
- GetWindowRect和GetClientRect的使用对比
- Fab CEO:创办四家公司教给我的90件事
- PHP和ActiveMQ集成
- 黑莓9900 只能用WIFI登录qq 不能用手机网络登录qq
- oracle查询所有表名
- LeetCode: Minimum Window Substring
- 修改网页编码出现的问题
- android之使用get和post方式向服务器提交请求