5555533
Test instructions: give you a V-liter paint, give the number of words 1--9 the corresponding paint cost, so that you use so much paint to draw the largest numbers.
Problem solving ideas;
/*
The greedy thought of this question is quite obvious. We want to make the number as large as possible, then we must ensure that the number of the place to be as long as possible
As long as possible on the basis, let the high number as large as possible, this is our greedy strategy. We know that by dividing the smallest number, you can
The number of giving way is the longest, but the longest can be obtained not only by the smallest number. such as: V=5 a={2,3,24,32,31,14,15,7,9},
Although the maximum length can be obtained is 2, and by dividing by 2 can result in 11, but the best result is 21. So as long as we can
It is guaranteed that the high-order number we get is larger and the number of digits is equal than the minimum number chosen.
*/
#include <bits/stdc++.h>using namespace Std;const int inf=1e9;int digit[20];int main () { int n,i,v,j,k,minv, AI; while (scanf ("%d", &v)!=eof) { minv=inf; for (i=1;i<=9;i++) { scanf ("%d", &digit[i]); minv=minv>digit[i]?digit[i]:minv; } if (minv>v) { printf (" -1\n"); Continue; } for (i=v/minv;i>=1;i--) {//Current dye If dye minimum cost that number can be dyed how many bits for (j=9;j>=1;j--) { //from large to small traverse the number if (v>= digit[j]&& (V-digit[j])/minv+1>=i) { //The current dye can dye a larger number and guarantee the same number of digits that can be dyed with the least amount of dye //greedy selection of the number printf ("%d", j); V-=DIGIT[J];}} } printf ("\ n"); } return 0;}