Created
May 10, 2016 17:02
-
-
Save joaogui1/84d46358b6ffbd8b2303d585664455ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstring> | |
#include <algorithm> | |
#define INF 999999999 | |
using namespace std; | |
int dp [1000500]; | |
int main() | |
{ | |
int T; | |
scanf("%d", &T); | |
for(int z = 0; z< T; z++) { | |
int coin[100], val, n, i, j; | |
memset(dp, 0, sizeof(dp)); | |
scanf("%d%d", &n, &val); | |
for(int i =1;i<=n;i++) | |
scanf("%d", &coin[i]); | |
dp[0] = 0; | |
for(i=1;i<=val;i++) dp[i] = INF; | |
for(i=1;i<=val;i++) | |
{ | |
for(j=1;j<=n;j++) | |
{ | |
if(i - coin[j]>=0) | |
{ | |
dp[i] = min(dp[i], dp[i-coin[j]] + 1); | |
} | |
} | |
} | |
printf("%d\n", dp[val]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment