Question Link : http://www.spoj.com/problems/MIXTURES/
My Solution Link :http://ideone.com/h6jHlv
Didn’t understand why the logic is wrong.
cost[i][j] = min( cost[i][j-1] + colorsum(i,j-1)*cost[j][j] , cost[i+1][j] + colorsum(i+1,j)*cost[i][i] )
=======
Wrong for trivial cases.
In case of only one color, your code return non-zero value.
It should return 0,because no mixture is possible.
The method of input here is different -
There will be a number of test cases in the input.
The first line of each test case will contain n,
Usually you may use
int t,n;
cin>>t;
while(t–){
cin>>n;
…
}
`
But You have to use the following snippet for this-
int n;
while( cin>>n )
{//Code}