1

伙计们这是问题

在一场锦标赛中,N 名玩家互相对战一次。每场比赛都会导致任一玩家获胜。没有关系。您已经给出了一张记分卡,其中包含每个玩家在比赛结束时的得分。玩家的得分是玩家在锦标赛中赢得的总局数。然而,一些球员的分数可能已经从记分卡中删除了。有多少可能的记分卡与输入记分卡一致?

输入:第一行包含案例 T 的数量。接下来是 T 案例。每个案例在第一行包含数字 N,然后在第二行包含 N 个数字。第 i 个数字表示 s_i,即第 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;
    }
4

0 回答 0