CCC '09 J2 - Old Fishin' Hole

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
Canadian Computing Competition: 2009 Stage 1, Junior #2

Fishing habitat and fish species are a resource that must be carefully managed to ensure that they will be there for the future. Accordingly, fishing limits have been established for a particular river based on the population of each species. Specifically, points are associated with the fish caught and the total points you catch must be less than or equal to the points allowed for that river.

As an example, suppose each brown trout counts as 2 points, each northern pike counts as 5 points and each yellow pickerel counts as 2 points, and the total points allowed must be less than or equal to 12. One acceptable catch could consist of 3 brown trout and 1 northern pike, but, other combinations would also be allowed.

Your job is to write a program to input the points allocated for a river, and find how many different ways an angler who catches at least one fish can stay within his/her limit.

Input Specification

You will be given 4 integers, one per line, representing trout points, pike points, pickerel points, and total points allowed in that order.

You can assume that each integer will be greater than 0 and less than or equal to 100.

Output Specification

For each different combination of fish caught, output the combination of brown trout, northern pike, and yellow pickerel in that order. The combinations may be listed in any order. The last line of output should display the total number of unique ways to catch fish within the established limit.

Sample Input


Sample Output

1 Brown Trout, 0 Northern Pike, 0 Yellow Pickerel
2 Brown Trout, 0 Northern Pike, 0 Yellow Pickerel
0 Brown Trout, 1 Northern Pike, 0 Yellow Pickerel
Number of ways to catch fish: 3


  • -2
    QiQi  commented on Nov. 28, 2021, 8:29 p.m.

    If you use python, it's a good idea to use a nested for loop or your code might not include "1 Brown Trout, 1 Northern Pike, 1 Yellow Pickerel" if you input 1, 1, 1, and 3.

  • 0
    zxcvbnmasdfghjklqwertyuiop  commented on Aug. 29, 2021, 11:47 p.m.

    i dont get what the question means can someone help me

  • 15
    cyopotatoe  commented on July 20, 2020, 2:50 p.m.

    I don't see any mass downvotes :0

  • 1
    Evan  commented on April 1, 2020, 3:42 p.m. edit 2

    Im just imagining someone using dfs/memoization for this question lol

  • 0
    WEAVER  commented on April 15, 2019, 5:39 p.m.

    Hi I am new to coding. Can someone plz try and help me

    • 3
      Tim2004  commented on July 27, 2019, 7:24 p.m. edited

      You should go do J1 first

    • 2
      p1geon  commented on April 16, 2019, 10:17 p.m.

      you can head over to the dmoj slack for help

  • 2
    IanHu  commented on Dec. 28, 2018, 10:37 p.m.

    What's wrong with my code?!!! It works perfectly in eclipse but gets WA here? HELP ME PLEZ!

    • 0
      magicalsoup  commented on Dec. 29, 2018, 3:50 p.m. edited

      um, your code doesn't seem right at this line

      if(rr != 0 || gg!=0 || pp!= 0)

      • 0
        IanHu  commented on Jan. 26, 2019, 11:09 p.m.


      • 0
        NeverDrinkAndDerive1  commented on Jan. 6, 2019, 10:13 a.m.

        how do you check other people's code? I'd like to help but idk how...

  • 0
    tev  commented on Sept. 10, 2018, 10:22 a.m. edited


  • 3
    Jerry_Gu  commented on Nov. 14, 2017, 12:12 p.m.

    When I use my code on NetBeans it works perfectly fine but when I submit it, the answer prints the first line and then only prints the amount of brown trout on second line and nothing else.

    • 1
      Arihan10  commented on Feb. 7, 2019, 9:57 a.m. edited

      It shows you a clipped version of your output.

      Your output (clipped)

  • 1
    hahahajokes  commented on Sept. 4, 2017, 6:51 p.m.

    Can someone please check my answer, I don't know where I did wrong.

    • 1

      Me, too

  • 16
    Chensta  commented on April 26, 2017, 6:25 p.m.

    When you out put the same answers but in a different order :/