CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » September Long Contest » Counting Hexagons

Counting Hexagons

Problem code: CNTHEX

  • All Submissions

All submissions for this problem are available.

Dexter wants to make a hexagon by using six sticks for sides from a collection of sticks of lengths 1, 2, 3, ... N. Dexter will only make valid hexagons whose area is strictly positive.

He considers a hexagon "good" if the biggest stick has length at least L and lengths of all the other sticks are not more than X. A "good" hexagon does not have sticks of the same length more than K times. How many ways he can make a "good" hexagon?

For example, when N=8, L=7, X=5, K=3: { 1,2,2,5,5,7 } is a good hexagon but {1,2,2,2,2,7}, { 1,2,3,4,5,6},{1,2,3,4,6,7} are not .

Two hexagons are considered different if their side length sets are different. For example {1,2,3,4,5,6} , {1,1,1,2,2,3} and {1,1,2,2,2,3} are all different hexagons. But {1,2,3,4,5,6} and { 2,4,6,1,3,5} are not different.

Input

Input contains four integers N( 2 <= N <= 10^9) , L ( 2 <= L <= N and N-L<=100) , X( 1<=X< L ) and K ( 1 <= K <= 5) .

Output

Output the number of different ways to make a "good" hexagon % 1000000007.

Sample Input

10 8 6 2

Sample Output

374


Author: rustinpiece
Date Added: 6-08-2011
Time Limit: 6 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

are you sure the sample

angad @ 2 Sep 2011 03:55 AM
are you sure the sample output is 374? i am getting 378!!

anybody?? and it has to be a

angad @ 2 Sep 2011 12:34 PM
anybody?? and it has to be a multiple of 3 in the case of the sample input, no? i cant see how its 374! kindly confirm the output.

how to check valid hexagons

itsjishu @ 2 Sep 2011 08:08 PM
how to check valid hexagons whose area is strictly positive? ( hexagons aren't regular ones.)

amgad, can u explain how u

agneshreddy @ 2 Sep 2011 08:16 PM
amgad, can u explain how u got 378

I'm also getting 378

elixyra215amy @ 3 Sep 2011 12:32 AM
I'm also getting 378

The sample is correct. You

imran_adm @ 3 Sep 2011 12:44 AM
The sample is correct. You have to count only the valid hexagons( with a positive area). @ itsjishu : A valid hexagon with a positive area does not need to be a regular hexagon(http://en.wikipedia.org/wiki/Hexagon#Regular_hexagon).

@angad, i agree with u. d

bodmas @ 3 Sep 2011 01:21 AM
@angad, i agree with u. d sample output should be 378.

@angad.. answer is correct.

pborde @ 3 Sep 2011 01:28 AM
@angad.. answer is correct. think well on itsjishu's question. u'll get it

^ thanks. i see!

bodmas @ 3 Sep 2011 02:24 AM
^ thanks. i see!

my solution is saying time

elixyra215amy @ 3 Sep 2011 12:44 PM
my solution is saying time limit exceeded when it runs in just two seconds in my IDE codelite

I just don't really get the

james_d @ 6 Sep 2011 02:07 AM
I just don't really get the point between N and L. If N = 8, Dexter has a collection of sticks of lenght 1,2,3,4,5,6,7 and 8, why does L is set to 7? Isn't Nmax = 8, and so, L is useless... Sorry but english is not my native language so I've got some difficulties to understand some subjects... Thanks for helping.

I do not get the logic behind

vivekitbhu @ 7 Sep 2011 06:06 AM
I do not get the logic behind displaying the output % 1000000007 and not output % 1000000000...I mean what is the significance of 1000000007...why do we have 7 at the end??

@vivek:its a prime that's why

cool_prabhjot @ 7 Sep 2011 09:30 AM
@vivek:its a prime that's why and ans%1000...7 will give max unique soln's. Got that!

can any 1 tell me some other

remogoku @ 7 Sep 2011 12:36 PM
can any 1 tell me some other test cases,,

@admin: here in dis problem,

remogoku @ 8 Sep 2011 10:05 AM
@admin: here in dis problem, the ans must be 372 i think.. since the area of hexagon must b positive.. bcoz for L value 9, we get one hexagon less and for L value 10, we get 2 hexagon less.. so out of 375 combinations, we get 372 as the answer.. pls tell me, where i went worng..??

Can somebody plz tell the

phantom11 @ 9 Sep 2011 03:28 AM
Can somebody plz tell the cases in which the area is not positive

what does positive area mean?

sandeepbiddala @ 11 Sep 2011 10:49 AM
what does positive area mean?

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com