Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int c[5], amn = 50, dp[6][100],seq[10000];
- int main()
- {
- int j,i,coin,num,total_coin = 0,total_coin2=0,amount = 89;
- c[0] = 5;
- c[1] = 2;
- c[2] = 10;
- c[3] = 1;
- c[4] = 20;
- for (i = 0; i < 6; i++)
- {
- for (j = 0; j < 6; j++)
- {
- if (c[j] < c[i])
- {
- int tmp = c[i];
- c[i] = c[j];
- c[j] = tmp;
- }
- }
- }
- for(i=0;i<6;i++)
- {
- for(j=0;j<2005;j++)
- {
- dp[i][j] = -1;
- }
- }
- i = 0;
- while(amn>0)
- {
- if(c[i]<=amn)
- {
- coin = c[i];
- num = amn/coin;
- total_coin += num;
- amn = amn - num*coin;
- printf("Coin %d - %d times\n",c[i],num);
- }
- i++;
- }
- printf("Total Coin Need: %d \n\n\n",total_coin);
- i=0;
- while(amount>0)
- {
- if(c[i]<=amount)
- {
- coin = c[i];
- num = amount/coin;
- total_coin2 += num;
- amount = amount - num*coin;
- printf("Coin %d - %d times\n",c[i],num);
- }
- i++;
- }
- printf("Total Coin Need: %d \n",total_coin2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement