Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #define INFINITO 100000000
  5.  
  6. int menor(int a,int b)
  7. {
  8. if(a<=b)
  9. return a;
  10. else
  11. return b;
  12. }
  13.  
  14.  
  15.  
  16.  
  17. int main(int argc, char const *argv[])
  18. {
  19.  
  20. int t,m,nSize,i,j;
  21. int n[26];
  22. int parcial[1000001];
  23.  
  24. scanf("%d",&t);
  25. while(t--)
  26. {
  27. scanf("%d %d",&nSize,&m);
  28. for (i = 0; i < nSize; i++)
  29. scanf("%d",&n[i]);
  30.  
  31. parcial[0]=0;
  32.  
  33. for (i = 1; i <= m; i++)
  34. {
  35. parcial[i] = INFINITO;
  36. for(j=0;j<nSize;j++)
  37. {
  38. if(n[j] <= i)
  39. {
  40. parcial[i] = menor(parcial[i],parcial[i-n[j]]+1);
  41. }
  42. }
  43. }
  44. printf("%d\n",parcial[m]);
  45. }
  46.  
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement