みんな、これが質問です
トーナメントでは、N 人のプレイヤーが 1 度だけ対戦します。各ゲームは、いずれかのプレイヤーが勝利します。関係はありません。トーナメント終了時に各プレイヤーのスコアを含むスコアカードを渡しました。プレーヤーのスコアは、プレーヤーがトーナメントで勝ったゲームの合計数です。ただし、一部のプレーヤーのスコアはスコアカードから消去されている可能性があります。入力スコアカードと一致するスコアカードはいくつありますか?
入力: 最初の行にはケース数 T が含まれます。T ケースが続きます。各ケースには、最初の行に数値 N が含まれ、2 行目に N の数値が続きます。i 番目の数字は、i 番目のプレイヤーのスコア s_i を表します。i 番目のプレーヤーのスコアが消去されている場合は、-1 で表されます。
出力: 各ケースの答えを含む T 行を出力します。各結果をモジュロ 1000000007 で出力します。
上記の質問の形式に減らしましたが、大きな入力で失敗しています。これは私に頭痛を与え始めています.どんな助けでも大歓迎です. 私は次のコードを持っています..コーナーケースで何か不足しています。
#include<stdio.h>
long long solutionMatrix[781][41];
long long
noOfWays (int gamesUndecided, int inHowMany, int noOfPlayers)
{
if (inHowMany > 0 && gamesUndecided >= 0)
{
int i;
long long result;
for (i = noOfPlayers - 1, result = 0; i >= 0; i--)
{
if((gamesUndecided-i)>=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 && 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 < noOfPlayers; i++)
{
if (score[i] != -1)
{
if (score[i] >= 0 && score[i] <= noOfPlayers - 1)
{
sumOfGames += score[i];
}
else
return 0;
}
else
unDecided++;
}
if (sumOfGames > maxGames || (unDecided==0 && sumOfGames < maxGames))
return 0;
if (sumOfGames==maxGames && unDecided==0)
return 1;
else
{
int j;
for (i = 0; i < 781; i++)
for (j = 0; j < 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", &noOfTestCases);
for (; noOfTestCases > 0; noOfTestCases--)
{
int noOfPlayers;
scanf ("%d", &noOfPlayers);
int i;
for (i = 0; i < noOfPlayers; i++)
{
scanf ("%d", score + i);
}
printf ("%lld\n", possibleCards (score, noOfPlayers));
}
return 0;
}