static int* Min;static int* Max;void LeastCoin2(int* Value, int Len, int *d, int Goal) {for(int i = 1; i <= Goal; i++){for(int j = 0; j < Len; j++){if(i >= Value[j]) {
Int distance = I-value [J]; int temp1 = min [distance] + 1; int temp2 = MAX [distance] + 1; min [I] = min [I] <temp1? Min [I]: temp1; Max [I] = MAX [I]> temp2? Max [I]: temp2 ;}}} void wleastcoin2 (int * value, int Len, int goal) {int * D = new int [goal + 1]; if (D = NULL) {printf ("malloc fail \ n");} memset (D,-1, sizeof (INT) * (goal + 1 )); d [0] = 0; printf ("goal: % d \ n", goal); min = new int [goal + 1]; for (INT I = 0; I <goal + 1; I ++) {Min [I] = 1 <10; // cannot be too large to prevent overflow} min [0] = 0; max = new int [goal + 1]; memset (max, 0, sizeof (INT) * (goal + 1); leastcoin2 (value, Len, D, goal ); for (INT I = 0; I <= goal; I ++) {printf ("% d", Min [I]); // Min [goal] min} printf ("\ n"); For (INT I = 0; I <= goal; I ++) {printf ("% d ", max [I]); // MAX [goal] Max} printf ("\ n ");}
Primary coin maximum and minimum problem push Method