https://ide.codingblocks.com/s/356994 here is the code the for find number of ways to get given amount with given coins , can u mark error or mistakes plz??
In order we want total number of ways to get given amount with given m coins
Hey @Ashu1318
line 20
cin>>n>>m;
Also
for(int j=0;j<m;j++){ //this should come first
for(int i=1;i<=n;i++){ //this should come later
if(i-a[j]>=0){
dp[i]+=dp[i-a[j]];
}
}
}
If u dont understand why loops are swapped then do a dry run in both the cases and you will see that in earlier version u are taking duplicates
If this resolves your query then please mark it as resolved
okay grt but how do we came to know about swapping loops means in what other types of que this is req ??
Hey @Ashu1318
Yaar Its not like that ,u have written them in wrong order, but for me the reverse order was correct.
In some problems bothways will work .
So its kind of depends problem to problem and there is no specific set of questions or something like that.