递归 打靶子问题
原文发布时间为:2009-03-01 —— 来源于本人的百度文章 [由搬家工具导入]
using System;
//using System.Collections.Generic;
//using System.Text;
namespace digui1
{
public class Class2
{
public static int sum=0;
public static int[] store=new int[10];
public static void Main()
{
fun(90, 9);
Console.WriteLine("总数为{0}", sum);
Console.ReadLine();
}
public static void fun(int score, int num)
{
if (score < 0 || score > (num + 1) * 10)
return;
if (num == 0)
{
store[num] = score;
Output();
return;
}
for (int i = 0; i <= 10; i++)
{
store[num] = i;
fun(score - i, num - 1);
}
}
public static void Output()
{
for (int i = 9; i >= 0; i--)
{
Console.Write("{0} ", store[i]);
}
Console.WriteLine();
++sum;
}
}
}