Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Some problems with your code:</p> <pre><code>int compare(const struct pair *elem1 ,const struct pair *elem2) { if ( elem2-&gt;coin &gt; elem1-&gt;coin &amp;&amp; elem2-&gt;numberofcoin&gt;0) return 1; else return -1; } </code></pre> <p>This comparison function isn't suitable for being passed to <code>qsort</code>. It doesn't return 0 for equal arguments, and <code>compare(x,y) == -1 == compare(y,x)</code> can happen. Thus <code>qsort</code> could loop with that comparison function, or produce incorrect results. However, with the data you get, that may not bite you.</p> <pre><code>for(i=0;i&lt;nc;i++) { a[i].numberofcoin=amount/a[i].coin; } </code></pre> <p>What is the idea behind that loop? I can't make sense of it. Deleting that loop helped getting the correct result for the example test case and makes more sense, since you'd be interested in the available coins of that denomination.</p> <pre><code>if(a[j].numberofcoin&gt;0&amp;&amp;a[j].coin&lt;=current) { puts("case if\n"); a[j].numberofcoin--; ans+=wa(n-a[j].coin,a,numberofdenominations,a[j].numberofcoin); a[j].numberofcoin++; } </code></pre> <p>Passing <code>a[j].numberofcoin</code> as the <code>current</code> parameter to the recursive call doesn't make sense. Why would you only consider coins whose denomination is smaller than the number of coins left of some (possibly other) denomination? As is, that is what makes the test fail in the recursive call, so the recursion never goes beyond <code>amount - one_coin</code> in the example. Passing <code>a[j].coin</code> here would make sense to prune duplicates.</p> <pre><code>printf("%d\n",wa(amount,a,nc,10)); </code></pre> <p>Why are you limiting the considered denominations to a maximum of 10 in <code>main</code>? If there are larger denominations available, you would not consider any solutions using them.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload