봄꽃들이 만개하는 4월이다. 뭐 같이 보러갈 사람도 없고 출퇴근 길에 잠깐 잠깐 보는게 전부인 개발자 1인이다. 4월 첫 째 주를 되돌아본다.
import java.io.*;
import java.util.HashSet;
import java.util.Set;
public class Main {
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
Solution s = new Solution();
System.out.println(s.solution(getInput(br)));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static int getInput(BufferedReader br) throws IOException {
return Integer.parseInt(br.readLine());
}
}
class Solution {
public int solution(int num) {
CombinationResolver cr = new CombinationResolver(num);
return cr.getResult();
}
private class CombinationResolver {
int select;
int[] combinated;
int[] group = {1, 5, 10, 50};
Set<Integer> result = new HashSet<>();
public CombinationResolver(int num) {
this.select = num;
this.combinated = new int[num];
}
public int getResult() {
combinate(0, 0);
return this.result.size();
}
private void combinate(int cnt, int start) {
if (cnt == this.select) {
saveCombinated();
return;
}
for (int i = start; i < this.group.length; i++) {
this.combinated[cnt] = this.group[i];
combinate(cnt + 1, i);
}
}
private void saveCombinated() {
int saveNum = 0;
for (int i : this.combinated) {
saveNum += i;
}
this.result.add(saveNum);
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
Input ip = getInput(br);
Solution s = new Solution();
System.out.println(s.solution(ip.gain, ip.weightLoss));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static Input getInput(BufferedReader br) throws IOException {
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int len = Integer.parseInt(st.nextToken());
int weightloss = Integer.parseInt(st.nextToken());
int[] gain = new int[len];
st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < gain.length; i++) {
gain[i] = Integer.parseInt(st.nextToken());
}
return new Input(gain, weightloss);
}
private static class Input {
int[] gain;
int weightLoss;
public Input(int[] gain, int weightLoss) {
this.gain = gain;
this.weightLoss = weightLoss;
}
}
}
class Solution {
public int solution(int[] gain, int weightloss) {
PermutationResolver pr = new PermutationResolver(gain, weightloss);
return pr.getResult();
}
private class PermutationResolver {
int[] group;
int weightloss;
int[] permutated;
boolean[] isUsed;
int result = 0;
public PermutationResolver(int[] group, int weightloss) {
this.group = group;
this.weightloss = weightloss;
this.permutated = new int[this.group.length];
this.isUsed = new boolean[this.group.length];
}
public int getResult() {
permutate(0);
return this.result;
}
private void permutate(int cnt) {
if (cnt == this.group.length) {
savePermutated();
return;
}
for (int i = 0; i < this.group.length; i++) {
if(this.isUsed[i]) continue;
this.isUsed[i] = true;
this.permutated[cnt] = this.group[i];
permutate(cnt + 1);
this.isUsed[i] = false;
}
}
private void savePermutated() {
int weight = 500;
boolean isGood = true;
for (int i : this.permutated) {
weight += i;
weight -= this.weightloss;
if (weight < 500) {
isGood = false;
break;
}
}
if(isGood) this.result++;
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
Solution s = new Solution();
System.out.println(s.solution(getInput(br)));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static int[] getInput(BufferedReader br) throws IOException {
int len = Integer.parseInt(br.readLine());
int[] arr = new int[len];
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < arr.length; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
return arr;
}
}
class Solution {
public int solution(int[] arr) {
BacktrackResolver br = new BacktrackResolver(arr, getSumOfArr(arr));
return br.getResult();
}
private int getSumOfArr(int[] arr) {
int result = 0;
for (int i : arr) {
result += i;
}
return result;
}
private class BacktrackResolver{
int[] arr;
int[] subset;
public BacktrackResolver(int[] arr, int sumOfArr) {
Arrays.sort(arr);
this.arr = arr;
this.subset = new int[sumOfArr + 2];
}
public int getResult() {
backtrack(0, 0);
for (int i = 1; i < this.subset.length; i++) {
if(this.subset[i] == 0) return i;
}
return -1;
}
private void backtrack(int cnt, int sum) {
if (cnt == this.arr.length) {
saveSum(sum);
return;
}
backtrack(cnt + 1, sum);
backtrack(cnt + 1, sum + this.arr[cnt]);
}
private void saveSum(int sum) {
this.subset[sum] = 1;
}
}
}