Best Answer BobbyGo, 21 May 2013 - 09:18 PM

Spoiler for looks like

Go to the full post
Plant 1: 10 to City 2 @ $6 and 25 to City 3 @ $10

Plant 2: 45 to City 1 @ $9 and 5 to City 3 @ $13

Plant 3: 10 to City 2 @ $9 and 30 to City 4 @ $5

Total Cost = $1020

Spoiler for code

As par for the course, this could probably have be made a lot more elegantly, but it seems to get the job done.

Fair warning: this took about 20 seconds to spit out an answer. Feel free to uncomment the cout after the first for loop if you are really into countdowns.

int a, b, c, d, e, f, g, h, i, j, k, l, a1, b1, c1, d1, e1, f1, g1, h1, i1, j5, k1, l1, money=10000; int main() { for(a=35; a>=0; a--) { //cout<<a<<endl; for(b=((35-a)>20 ? 20 : (35-a)); b>=0; b--) { for(c=((35-(a+b))>30 ? 30 : (35-(a+b))); c>=0; c--) { d=35-(a+b+c); for(e=45-a; e>=0; e--) { for(f=((50-e)>20 ? 20 : (50-e)); f>=0; f--) { for(g=((50-(e+f))>30 ? 30 : (50-(e+f))); g>=0; g--) { h=50-(e+f+g); for(i=((a+e)<5 ? 0 : 45-(a+e)); i>=0; i--) { if(a+e+i==45) { for(j=((40-i)>20 ? 20 : (40-i)); j>=0; j--) { if(b+f+j==20) { for(k=((40-(i+j))>30 ? 30 : (40-(i+j))); k>=0; k--) { if(c+g+k==30) { l=40-(i+j+k); if(d+h+l==30 and (8*a+6*b+10*c+9*d+9*e+12*f+13*g+7*h+14*i+9*j+16*k+5*l)<=money) { money=(8*a+6*b+10*c+9*d+9*e+12*f+13*g+7*h+14*i+9*j+16*k+5*l); a1=a;b1=b;c1=c;d1=d; e1=e;f1=f;g1=g;h1=h; i1=i;j5=j;k1=k;l1=l; } } } } } } } } } } } } } cout<<a1<<" "<<b1<<" "<<c1<<" "<<d1<<endl<<e1<<" "<<f1<<" "<<g1<<" "<<h1<<endl<<i1<<" "<<j5<<" "<<k1<<" "<<l1<<endl<<"= $"<<money<<endl; return 0; }