Coins Change Problem - (Recursive+DP+Code)// Code Spectrum

Pubblicato il: 05 febbraio 2023
sul canale di: Code Spectrum
30
1

Watch it for revision...You can learn DP by analyzing the optimal substructure and overlapping subproblems.

Thank you, viewers. My name is Abhilash. I am a Ph.D. scholar at IIT Jammu, CSE Dept. I research in the field of Cryptology.

//Code//
#include stdio.h
int M[4][70];
int minVal(int x,int y){
if(x less than y)return x; else return y;
}
int main(){
int C[5]={1,5,8},n=3,V=10;
int i,j;
for(i=0;i is less than or equal to n;i++){
for(j=0;j is less than or equal to V;j++){
if(i==0 && j is greater than 0){
M[i][j]=9999;// 9999 == oo
}
else if(j==0){
M[i][j]=0;
}else if(j-C[i-1] is less than 0){
M[i][j]=M[i-1][j];
}
else{
M[i][j]=minVal(1+M[i][j-C[i-1]],0+M[i-1][j]);
}
printf("%d\t",M[i][j]);
}
printf("\n");
}
return 0;
}


In questa pagina del sito puoi guardare il video online Coins Change Problem - (Recursive+DP+Code)// Code Spectrum della durata di online in buona qualità , che l'utente ha caricato Code Spectrum 05 febbraio 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 30 volte e gli è piaciuto 1 spettatori. Buona visione!