jayantjha1109's blog

By jayantjha1109, history, 6 years ago, In English

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;

Please help. I am getting WA on few tests.

code-

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

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

  • Vote: I like it
  • +1
  • Vote: I do not like it

| Write comment?
»
6 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by jayantjha1109 (previous revision, new revision, compare).

»
6 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by jayantjha1109 (previous revision, new revision, compare).

»
6 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by jayantjha1109 (previous revision, new revision, compare).

»
6 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Use inverse modulo under 2 instead of just dividing the number.