>>903 #include <stdio.h>
#include <stdlib.h>
void cpy(int *dst, int *src, int size){ while(size--) *dst++ = *src++;}
void count_change(int n, int *p, int *cnt, int *min_cnt, int *min, int pos, int size){
int i;
if(n==0) {
int sum = 0;
for(i=0; i<size; i++) sum += cnt[i];
if(sum < *min) { *min = sum; cpy(min_cnt, cnt, size);}
return;}
if(pos==size) return;
for(i=0; i*p[pos]<=n; i++) {
cnt[pos] = i;
count_change(n-i*p[pos], p, cnt, min_cnt, min, pos+1,size);
cnt[pos] = 0;}}
int main(void){
int i, min, *p, *cnt, *min_cnt, size, n;
FILE *fp;
if((fp=fopen("data.txt", "r"))==NULL) return 0;
fscanf(fp, "%d", &size);
p = malloc(sizeof(int)*size);
cnt = malloc(sizeof(int)*size);
min_cnt = malloc(sizeof(int)*size);
for(i=0; i<size; i++) fscanf(fp, "%d", p + i);
while(fscanf(fp, "%d", &n) && n!=0) { min = n;
for(i=0; i<size; i++) cnt[i] = min_cnt[i] = 0;
count_change(n, p, cnt, min_cnt, &min, 0, size);
printf("%dyen,%dmai\n", n, min);
for(i=0; i<size; i++) if(min_cnt[i]) printf("(%d*%d)", p[i], min_cnt[i]);
putchar('\n');}
return 0;}