MixturesProblem code: MIXTURES |
All submissions for this problem are available.
Harry Potter has n mixtures in front of him, arranged in a row. Each mixture has one of 100 different colors (colors have numbers from 0 to 99).
He wants to mix all these mixtures together. At each step, he is going to take two mixtures that stand next to each other and mix them together, and put the resulting mixture in their place.
When mixing two mixtures of colors a and b, the resulting mixture will have the color (a+b) mod 100.
Also, there will be some smoke in the process. The amount of smoke generated when mixing two mixtures of colors a and b is a*b.
Find out what is the minimum amount of smoke that Harry can get when mixing all the mixtures together.
Input
There will be a number of test cases in the input.
The first line of each test case will contain n, the number of mixtures, 1 <= n <= 100.
The second line will contain n integers between 0 and 99 - the initial colors of the mixtures.
Output
For each test case, output the minimum amount of smoke.
Example
Input: 2 18 19 3 40 60 20 Output: 342 2400
In the second test case, there are two possibilities:
- first mix 40 and 60 (smoke: 2400), getting 0, then mix 0 and 20 (smoke: 0); total amount of smoke is 2400
- first mix 60 and 20 (smoke: 1200), getting 80, then mix 40 and 80 (smoke: 3200); total amount of smoke is 4400
The first scenario is the correct approach since it minimizes the amount of smoke produced.
| Author: | admin |
| Date Added: | 1-12-2008 |
| Time Limit: | 9 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, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
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. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - 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. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions

how do we know the input limit??
@hrishikesh Read input until you encounter an EOF.
how do I use EOF with scanf ?
scanf() returns the number of characters successfully read from stdin. Use this information to use EOF with scanf.
Can the color of the mixture repeat ?
I meant in a given set, could there be multiple mixtures of the same colors ?
There might be test cases like that.
Can the order of mixtures be
No. They are in a line.
No. They are in a line.
can we mix 40 and 20 skipping
can we mix 40 and 20 skipping the 60 in between?
I just answered that in the
I just answered that in the comment directly above yours..
Hello Stephen
Hello Stephen
can someone paste some tricky
can someone paste some tricky test case for this problem.Have broken my head but can't figure out the problem with my solution.
Have you checked your program
Have you checked your program for values of N for which you can verify the solution using brute-force?
Is there a limit to the size
Is there a limit to the size in which final answer of smoke would fit in ?
im using while(scanf("%d",&n)
im using
while(scanf("%d",&n) > 0){ // take n inputs and print output }
i guess it should terminate when there is no input?
anybody who has solved this
anybody who has solved this problem using memoization or using simple recurssion without getting TLE ? ? ?
@Ankush.. dude everyone has
@Ankush.. dude everyone has solved the problem via DP.. and if you are getting TLE and u think that u have implemented the DP correctly, the only probable reason is that you are not detecting the EOF properly.. thats why your code is never able to stop!!
can ne1 post the solution of
can ne1 post the solution of this prob...nt able to solve this...me a novice :(
i am learning dp could anyone
i am learning dp could anyone tell that is this is dynamic problem or greedy problem and how can i check out that is this dynamic problem or greedy.....???
can u people pls tell me the
can u people pls tell me the commands for taking the no if test cases pls...pls
Hey what will be the o/p of
Hey what will be the o/p of the following i/p
5
40 60 20 9 10
My ans is 2400
Succesfull submitter answers 2870
40*60 will be used first since (40+60)%100 gives us 0 that makes rest 0 , so the answer should be 2400
Yups answer is 2870 .. i
Yups answer is 2870 .. i forgot to add rest smoke..
hint : matrix multiplication
hint : matrix multiplication problem
please tell me for what input
please tell me for what input it will give incorrect answer.............??
#include<stdio.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int col[n+1],i,j,min,temp,x,y,k;
unsigned int fume;
fume=0;
for(i=0;i<n;i++)
{
scanf("%d",&col[i]);
}
i=0;
j=1;
min=1000;
while(n>1)
{
i=0;
j=1;
while(i!=n-1)
{
while(j!=n)
{
temp=(col[i]+col[j])%100;
if(temp<min)
{
min=temp;
x=i;
y=j;
}
j++;
}
i++;
}
fume=fume+col[x]*col[y];
col[x]=min;
min=1000;
for(k=y;k<n-1;k++)
{
col[k]=col[k+1];
}
n--;
}
printf("%dn",fume);
}
return 0;
}
sir, will u give me the input
sir,
will u give me the input file for which it gives the incorrect answer............???
can anyone pls tell me if the
can anyone pls tell me if the following approaach is correct or not
everytime we chose those two adjacent mixtures which giv least value of (a+b)mod 100 as compared to other pairs
Can you prove that will
Can you prove that will always lead to the best answer? If you can't prove it, it's normally wrong.
thanx alot stephen ala got AC
thanx alot stephen ala got AC
@Stephen: Can you please give
@Stephen: Can you please give me a testcase where my solution is giving the incorrect result?
Hi Stephen, I've tried many
Hi Stephen, I've tried many testcases and all given correct answers. I'm not sure which one creating the problem. Can you please help me by providing a testcase?
Your code doesn't even work
Your code doesn't even work on the sample input.
Hi Stephen, In my end it is
Hi Stephen, In my end it is perfectly work for the sample input as well as the inputs written in the comments. I also tried with 100 inputs and got the correct result. Can you please let me know the poblem testcase?
Understood the problem. I've
Understood the problem. I've taken input from console instead of the file.
Nothing is wrong with taking
Nothing is wrong with taking the input from a console; but your program only outputs 342 for the sample input; it never gets to output 2400 as well.
http://www.codechef.com/views
http://www.codechef.com/viewsolution/475504
can sum1 tell what is wrong in my solution. It is giving correct answers for the sample input and also of the random inputs. I have checked it with solutions submitted by other persons. But on submitting my solution it shows wrong answer.
Those who are getting wrong
Those who are getting wrong answers,can check some test cases here:https://www.spoj.pl/forum/viewtopic.php?f=3&t=4007&p=16920&hilit=MIXTURES#p16920
760 44 33 67 9 90 34 for this
7
60 44 33 67 9 90 34
for this case on the mention site answer is 8207
and my ans is 6159
60*44+33*67+0*4+4*9+13*90+3*34=6159
it can cum as
60 44 0 9 90 34
04 0 9 90 34
4 9 90 34
13 90 34
3 34
37
so explain this answer...
leave it i was checking from
leave it i was checking from wrong soln by mistake..
My solution working proper
same here. i am getting right
Hi.. My program is working
Make sure you handle the case
Given in the