We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #53: Combinatoric selections
  4. Discussions

Project Euler #53: Combinatoric selections

Problem
Submissions
Leaderboard
Discussions

    You are viewing a single comment's thread. Return to all comments →

  • Piyushgrwl
    6 years ago+ 3 comments

    My code is passing all the test cases except no.3. Its showing wrong answer. Please tell me what is wrong in this code.


    unsigned long long C[1001][1001], i, j, k, N, K, coun = 0, flag = 0;

    int main()
    {
    cin >> N >> K;
    for (i = 1; i <= 1000 && i <= N; i ++)
    {
    for (j = 0; j <= i; j ++)
    {
    if (j == 0 || j == i)
    C[i][j] = 1;
    else
    {
    if (j == 1 || j == i-1)
    C[i][j] = i;
    else
    C[i][j] = C[i-1][j] + C[i-1][j-1];
    }
    }
    }
    for (i = 1; i <= N; i ++)
    {
    flag = 0;
    for (j = 0; j <= i; j ++)
    {
    if (C[i][j] > K)
    {
    flag = 1;
    break;
    }
    }
    if (flag == 1)
    coun += (i - 2*j + 1);
    }
    cout << coun;
    return 0;
    }


    Thanks !!

    1|
    Permalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature