You are not logged in. Please login at www.codechef.com to post your questions!

×

WA on codeforces question. Logic Error ?

https://codeforces.com/problemset/problem/118/D

In the above question, most of the people have solved it using dp but i am trying it using pnc.

My approach is that first i am calculating all possible ways of arranging n1 soldiers and n2 horses which is (n1+n2)C(n1) ways.

Then i am grouping (k1+1) soldiers and calculating all possible ways of arranging them. This value is equal to (n1-k1+n2)!/(n1-k1-1)!(n2)!. This value should be substracted from the total ways.

Then i am grouping (k2+1) soldiers and calculating all possible ways of arranging them. This value is equal to (n2-k2+n1)!/(n2-k2-1)!(n1)!. This value should be substracted from the total ways.

Then i am calculating the intersection of the above two cases as it has been substracted two times from the total cases. This value is equal to (n1-k1+n2-k2)!/(n1-k1-1)!(n2-k2-1)!. This value is added in total possible ways to eliminate double counting from the above two cases.

I have also taken care of the fact that we will group soldiers or horses only when it would be possible to group them i.e., (n1>k1) , (n2>k2) for respective cases.

I am getting WA. I cant figure out which case i am missing and need help.

Here is my code https://codeforces.com/contest/118/submission/48692151

Thanks in advance for the time and help. ;)

asked 22 Jan, 23:06

incognito_nag's gravatar image

5★incognito_nag
11
accept rate: 0%

for proper answer view you can look on this solution

https://codeforces.com/contest/118/submission/48761414

(22 Jan, 23:11) incognito_nag5★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×2,169
×678
×2
×2

question asked: 22 Jan, 23:06

question was seen: 56 times

last updated: 22 Jan, 23:11