Skip to content

Instantly share code, notes, and snippets.

@fpdjsns
Last active March 8, 2017 10:33
Show Gist options
  • Save fpdjsns/e280f244b56eaab4f921dbe07a209acb to your computer and use it in GitHub Desktop.
Save fpdjsns/e280f244b56eaab4f921dbe07a209acb to your computer and use it in GitHub Desktop.
CC(Coin Change) 동전 교환
#include<iostream>
using namespace std;
int main()
{
int n, money, cost;
int d[11][1000] = { 0 };
cin >> n >> money;
d[0][0] = 1;
for (int i = 1; i <= n; i++)
{
cin >> cost;
for (int j = 0; j <= money; j++)
{
if (j < cost)//0 ~ j-1 까지는 변함 없음
d[i][j] = d[i - 1][j];
else
d[i][j] = d[i][j - cost] + d[i - 1][j];
}
}
cout << d[n][money];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment