[BOJ] 3040 백설 공주와 일곱 난쟁이
Algorithm 2023. 2. 6. 22:14반응형
https://www.acmicpc.net/problem/3040
조합
using System;
using System.Linq;
namespace smilejsu
{
class Program
{
private static int[] arr = new int[9];
static void Main(string[] args)
{
for (int i = 0; i < 9; i++)
{
arr[i] = int.Parse(Console.ReadLine());
}
string input = "012345678";
int combinationLength = 7;
GenerateCombinations(input, "", combinationLength, 0);
}
static void GenerateCombinations(string input, string output, int combinationLength, int index)
{
//Console.WriteLine("{0}", output);
if (output.Length == combinationLength)
{
int sum = 0;
for (int i = 0; i < output.Length; i++)
{
int idx = int.Parse(output[i].ToString());
sum += arr[idx];
//Console.Write("{0} ", idx);
}
//Console.WriteLine();
if (sum == 100)
{
for (int i = 0; i < output.Length; i++)
{
int idx = int.Parse(output[i].ToString());
//sum += arr[idx];
Console.WriteLine("{0}", arr[idx]);
}
//Console.WriteLine(output);
}
return;
}
if (index >= input.Length)
{
return;
}
GenerateCombinations(input, output + input[index], combinationLength, index + 1);
GenerateCombinations(input, output, combinationLength, index + 1);
}
}
}
반응형
'Algorithm' 카테고리의 다른 글
[BOJ] 2108 통계학 (0) | 2023.02.13 |
---|---|
[BOJ] 1297 TV 크기 (0) | 2023.02.07 |
[BOJ] 2581 소수 (0) | 2023.02.05 |
[BOJ/C#] 11945 뜨거운 붕어빵 (0) | 2023.02.02 |
[BOJ/C#] 4796 캠핑 (0) | 2023.01.31 |