链接: https://pan.baidu.com/s/19ci2sXZTjurqNzSlzbY3Sw
提取码: 4vmh
链接: https://pan.baidu.com/s/19ci2sXZTjurqNzSlzbY3Sw
提取码: 4vmh
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp9
{
class Program
{
static void Main(string[] args)
{
while (true)
{
Test t = new Test();
t.test();
}
}
}
class Test
{
int types;
int[] curs,curss;
int count;
List<int[]> results;
public void test()
{
types=int.Parse(Console.ReadLine());
curs =new int[types];
curss = new int[types];
results = new List<int[]>();
string[] tmp= Console.ReadLine().Split(' ');
for (int i = 0; i < types; i++)
{
curs[i] = int.Parse(tmp[i]);
}
count = int.Parse(Console.ReadLine());
cal(0, 0);
for (int i = 0; i < results.Count; i++)
{
string ss = "";
for (int j = 0; j < results[i].Length; j++)
{
for (int k = 0; k < results[i][j]; k++)
{
ss += curs[j];
ss += " ";
}
}
Console.WriteLine(ss);
//ss += "\n";
}
//Console.WriteLine(ss);
}
void cal(int b,int sum)
{
for (int i = (count-sum)/curs[b]; i >=0; i--)
{
curss[b] = i;
int tmp = sum + i * curs[b];
if (tmp == count)
{
int[] cursst = new int[types];
for (int j = 0; j < types; j++)
{
cursst[j] = curss[j];
}
results.Add(cursst);
}
else
{
if (b+1<types && tmp<count)
{
cal(b + 1, tmp);
}
}
}
curss[b] = 0;
}
}
}