Getting WA on CSES Two sets — II question

Revision en4, by jayantjha1109, 2020-08-28 11:03:59

I am trying the CSES problem set. I am getting WA on a few tests in Two Sets — II question. Here is the link for the question https://cses.fi/problemset/task/1093

My approach is to create a dp[i][j] which stores the number of ways to get sum i using first j indices. My target is to get sum n*(n-1)/4 . Formula I use is- dp[i][j]=dp[i][j-1]+dp[i-j][j-1];

I initialized dp[0][i] to 1 for all i<=n bcoz the only possible way is to select no indice at all. And also dp[i][0] to 0 for all 1<=i<=target bcoz its not possible to create a sum using no digits at all. I then print (dp[target][n])/2;

code-

https://codeforces.com/contest/1400/submission/91190026

The question is irrelevant in this link. Only the code is relevant

#### History

Revisions

Rev. Lang. By When Δ Comment
en4 jayantjha1109 2020-08-28 11:03:59 1244
en3 jayantjha1109 2020-08-28 10:59:16 1333
en2 jayantjha1109 2020-08-28 10:52:28 35 Tiny change: ' at all.\n\nPlease' -> ' at all.\nI then print (dp[target][n])/2;\n\nPlease'
en1 jayantjha1109 2020-08-28 10:51:28 677 Initial revision (published)