WA in MIXTURES - Spoj

Question Link : SPOJ.com - Problem MIXTURES

My Solution Link :h6jHlv - Online C++0x Compiler & Debugging Tool - Ideone.com

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.

cost[i][i]=0;

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}