백준 6126 c++

magicdrill·2024년 7월 1일

백준 문제풀이

목록 보기
381/673

백준 6126 c++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void input_coin(vector<int>& coin, int *N)
{
	int V;
	int i, temp;

	cin >> V >> *N;
	for (i = 0; i < V; i++)
	{
		cin >> temp;
		coin.push_back(temp);
	}

	return;
}

void find_answer(vector<int> coin, int N)
{
	long long total = 0;
	int i;
	vector<long long> coin_dp(N + 1, 0);

	coin_dp[0] = 1;
	for (int coin_unit : coin)
	{
		for (i = coin_unit; i <= N; i++)
		{
			coin_dp[i] += coin_dp[i - coin_unit];
		}
	}
	cout << coin_dp[N];

	return;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int N;
	vector <int> coin;

	input_coin(coin, &N);
	find_answer(coin, N);

	return 0;
}

0개의 댓글