Sei sulla pagina 1di 3

Login

Signup

Login or

Signup with
Have you tried CodeChefs "Code, Compile & Run" Its pretty cool. Try it out by pressing Ctrl+;
and
[X]
typing "ide"

PRACTICE

COMPETE

DISCUSS

COMMUNITY

HELP

ABOUT

Home Practice(easy) Chef and Combinatorics

Chef and Combinatorics

ALL SUBMISSIONS

Problem code: GERALD05


Like

SUBMIT

Share 10 people like this. Sign Up to see what your


friends like.

All submissions for this problem are available.

SUCCESSFUL SUBMISSIONS

Read problems statements in Mandarin Chinese here


User

Time Mem

Lang

Solution

Problem Statement

f03nix

0.00 2.7M

C++ 4.3.2

View

Chef studies combinatorics. He tries to group objects by their rang (a positive integer associated with
each object). He also gives the formula for calculating the number of different objects with rang N as
following:

mpthegreat_5

0.00 2.7M

C++ 4.3.2

View

ellg13

0.00 2.7M

C++ 4.3.2

View

vijay_pal

0.00 2.7M

C++ 4.3.2

View

jaimanoj

0.00 2.7M

C++ 4.3.2

View

architkhosla

0.00 2.7M

C++ 4.3.2

View

ashwin1907

0.00 2.7M

C++ 4.3.2

View

0.00 2.7M

C++ 4.3.2

View

0.00 2.7M

C++ 4.3.2

View

0.00 2.7M

C++ 4.3.2

View

idatarm

0.00 2.7M

C++ 4.3.2

View

sakib_rulez

0.00 2.8M

C++ 4.3.2

View

Read problems statements in Russian here

the number of different objects with rang N = F(N) = A0 + A1 * N + A2 * N2 + A3 * N3.


Now Chef wants to know how many different multisets of these objects exist such that sum of rangs of
the objects in the multiset equals to S. You are given the coefficients in F(N) and the target sum S.
Please, find the number of different multisets modulo 1,000,000,007.
You should consider a multiset as an unordered sequence of integers. Two multisets are different if and
only if there at least exists one element which occurs X times in the first multiset but Y times in the
second one, where (X Y).

Input
The first line of the input contains an integer T denoting the number of test cases. The description of T code_note
test cases follows.
na205
The first line of each test case contains four integers A0, A1, A2, A3. The second line contains an integer
S.
usaxena95

Output
For each test case, output a single line containing a single integer - the answer to the test case modulo
1,000,000,007.

Constraints
1 T 500
1 S 100
0 Ai 1000
Sum of all S for all test cases is not greater than 500. It's guaranteed that at least one Ai is nonzero.

1 of 7

HELP

Example
Input:
4
1000
1
1000
3
0100
2
2314
10
Output:
1
3
3
213986343

Explanation
Example case 2.
In the second example function looks as follows F(N) = 1. So for each rang there is a single object of the
rang. To get multiset with sum of rangs equal to 3, you can pick: three objects of rang 1, or one object of
rang 1 and one of rang 2, or only one object of rang 3.
Example case 3.

converted by W eb2PDFConvert.com

In the third example function looks as follows F(N) = N. So, you have one distinct object of rang 1, two
distinct objects of rang 2, three distinct objects of rang 3 and so on. To get
multiset with sum of rangs equal to 2, you can pick: two objects of rang 1, one of objects of rang 2 (two
ways).
Author:

gerald

Tester:

rustinpiece

Editorial

http://discuss.codechef.com/problems/GERALD05

Program should read from standard input and write to


standard output. After you submit a solution you can see
your results by clicking on the [My Submissions] tab on
the problem page. Below are the possible results:
Accepted Your program ran successfully and
gave a correct answer. If there is a score for the
problem, this will be displayed in parenthesis next to
the checkmark.

Date Added: 10-12-2013


Time Limit:

1 sec

Source
Limit:

50000 Bytes

Time Limit Exceeded


Your program was
compiled successfully, but it didn't stop before time
limit. Try optimizing your approach.

ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.8.1, CPP11,
Languages: CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA,
NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH
3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC

Wrong Answer Your program compiled and ran


succesfully but the output did not match the expected
output.
Runtime Error Your code compiled and ran but
encountered an error. The most common reasons are
using too much memory or dividing by zero. For the
specific error codes see the help section.

Comments

Compilation Error
Your code was unable to
compile. When you see this icon, click on it for more
information.

Please login at the top to post a comment.


chetan268code @ 28 Dec 2013 01:27 AM
In example case 2: If there is only one object of each rang, then how is it possible to use 3 objects of
rang one in this example.??

If you are still having problems, see a sample solution


here.

gifted @ 28 Dec 2013 11:19 AM


@chetan : you should look at the definition of multisets

tusharmarda @ 29 Dec 2013 07:53 PM


Does F(N) even have any use here?

codethrust @ 10 Jan 2014 03:15 PM


can anyone please give some more test cases...I am getting right answer for first 3 test cases...and I
cant imagine what's wrong with the fourth one as the calculations are not manually possible...also I
had created some test cases of my own and my code works for them... Are the following test cases
fine?? Input 2 2 0 0 0 3 0 0 0 2 4 Output- 14 572

sagnik_saha @ 15 Jan 2014 01:55 PM


I need some more test cases (with explanations) too. I seem to have the same problem as
"codethrust".(But his input 2 2 0 0 0 3 0 0 0 2 4 gives an output of 10 425 in my machine)

gsp94 @ 29 Jan 2014 06:36 PM


Mine is working for all the cases given here but it is still saying wrong answer. Where can I get more
test cases with the answers so I can at lease check for mistakes.

shashwatadi @ 27 Feb 2014 12:27 PM


The ans for test case 3 must've been 2(as explained)... I'm confused :(

rakespatni @ 4 Mar 2014 12:23 AM


what is the point in providing the equation of F(n).How does it even relate to the problem.??

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

The time now is: 01:19:46 PM


Your Ip: 50.97.53.245

CodeChef - A Platform for Aspiring Programmers

converted by W eb2PDFConvert.com

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.

converted by W eb2PDFConvert.com

Potrebbero piacerti anche