You are viewing a single comment's thread. Return to all 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 !!
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #53: Combinatoric selections
You are viewing a single comment's thread. Return to all 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 !!