Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic programming selecting tuples(size T) of nos with each not greater than k and sum S
    primarykey
    data
    text
    <p>Guys this is the question</p> <p>In a tournament, N players play against each other exactly once. Each game results in either of the player winning. There are no ties. You have given a scorecard containing the scores of each player at the end of the tournament. The score of a player is the total number of games the player won in the tournament. However, the scores of some players might have been erased from the scorecard. How many possible scorecards are consistent with the input scorecard?</p> <p>Input: The first line contains the number of cases T. T cases follow. Each case contains the number N on the first line followed by N numbers on the second line. The ith number denotes s_i, the score of the ith player. If the score of the ith player has been erased, it is represented by -1.</p> <p>Output: Output T lines, containing the answer for each case. Output each result modulo 1000000007.</p> <p><strong>I have reduced it to the above form of the question but it is failing on large inputs</strong>. This is starting to give me headaches.Any help will be appreciated. I have the following code..am i missing something any corner cases.</p> <pre><code> #include&lt;stdio.h&gt; long long solutionMatrix[781][41]; long long noOfWays (int gamesUndecided, int inHowMany, int noOfPlayers) { if (inHowMany &gt; 0 &amp;&amp; gamesUndecided &gt;= 0) { int i; long long result; for (i = noOfPlayers - 1, result = 0; i &gt;= 0; i--) { if((gamesUndecided-i)&gt;=0) { if (solutionMatrix[gamesUndecided - i][inHowMany - 1] == -1) solutionMatrix[gamesUndecided - i][inHowMany - 1] = noOfWays (gamesUndecided - i, inHowMany - 1, noOfPlayers); result += solutionMatrix[gamesUndecided - i][inHowMany - 1]; result %=1000000007L; } } return result%1000000007L; } else return (inHowMany == 0 &amp;&amp; gamesUndecided == 0) ? 1 : 0; } long long possibleCards (int score[], int noOfPlayers) { int i; int maxGames = (noOfPlayers * (noOfPlayers - 1)) / 2; int sumOfGames = 0, unDecided = 0; for (i = 0; i &lt; noOfPlayers; i++) { if (score[i] != -1) { if (score[i] &gt;= 0 &amp;&amp; score[i] &lt;= noOfPlayers - 1) { sumOfGames += score[i]; } else return 0; } else unDecided++; } if (sumOfGames &gt; maxGames || (unDecided==0 &amp;&amp; sumOfGames &lt; maxGames)) return 0; if (sumOfGames==maxGames &amp;&amp; unDecided==0) return 1; else { int j; for (i = 0; i &lt; 781; i++) for (j = 0; j &lt; 41; j++) solutionMatrix[i][j] = -1; return noOfWays (maxGames - sumOfGames, unDecided, noOfPlayers)%1000000007L; } } int main () { int noOfTestCases; int score[41]; printf("%u\n",0xffffffff); scanf ("%d", &amp;noOfTestCases); for (; noOfTestCases &gt; 0; noOfTestCases--) { int noOfPlayers; scanf ("%d", &amp;noOfPlayers); int i; for (i = 0; i &lt; noOfPlayers; i++) { scanf ("%d", score + i); } printf ("%lld\n", possibleCards (score, noOfPlayers)); } return 0; } </code></pre>
    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.
 

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