#include "stdio.h" #include "stdlib.h" unsigned min(unsigned a, unsigned b) { return a=d[n]? t[n]*(e-d[n]) :d[n]-e<=q[n]? c[n]*(d[n]-e) : 1000; for(k=n-0;printf("\n"),k>0;k--) for(e=0;e<=Emax;e++) { unsigned z=1000; for(x=0;x<=q[k];x++) if(ee=e+x-d[k],ee>=0 && ee<=Emax) z=min(z,c[k]*x+t[k]*ee+f[k+1][ee]); f[k][e] = z; printf("%5d",z); } for (k = 1, e = 0; k <= n; k++) { unsigned int z = f[k][e]; for(x=0;x<=q[k];x++) if(ee=e+x-d[k],ee>=0 && ee<=Emax) if(z==c[k]*x+t[k]*ee+f[k+1][ee]) break; printf("Au jour %d on produit %2d le stock devient %2d=%2d+%2d-%2d. Le cout est %2d=%2d+%2d*%2d+%2d*%2d\n", k, x, ee, e, x, d[k], f[k][e],f[k+1][ee],c[k],x,t[k],ee); e=ee; } return f[1][0]; } int main(int argc, char const *argv[]) { int n = 6; int d[] = {0, 5, 6, 6, 4, 5, 7}; int q[] = {0, 10, 10, 10, 10, 10, 10}; int c[] = {0, 3, 1, 2, 3, 1, 5}; int t[] = {0, 2, 2, 1, 2, 2, 10}; int cout = cout_min(n, d, q, t, c); printf("Cout min %d\n", cout); return 0; }