intsolve(int *array, int num, int budget) { int count = 0, i = 0; for (i = 0; i < num; i++) { if (budget < array[i]) continue; budget -= array[i]; if(budget >= 0) count++; } return count; }
intmain(void) { int m, i, j; int budget, num; int *price = NULL; while(scanf("%d", &m) != EOF) { for (i = 0; i < m; i++) { scanf("%d%d", &budget, &num); price = (int *)malloc(num*sizeof(int)); for (j = 0; j < num; j++) { scanf("%d", price+j); } qsort(price, num, sizeof(int), compare); printf("%d\n", num - solve(price, num, budget)); if (price) { free(price); price = NULL; } } } return0; }
intmain(void) { int count, n, i, j, y, k; while(scanf("%d", &count) != EOF) { for (k = 0; k < count; k++) { memset(num, 0, sizeof(num)); scanf("%d%d", &y, &n);
for (i = 0; i < n; i++) scanf("%d", &price[i]);
for (i = 0; i < n; i++) { for (j = y; j >= price[i]; j--) { num[j]=MAX(num[j], (num[j-price[i]]+1)); } }
intsolve(int *a, int len) { int pos, i,loops = 0; /* 有序的序列 */ int *b = (int *)malloc(len*sizeof(int)); int *map, *flags; memcpy(b, a, len*sizeof(int));
intmain() { int count; int n, m, i, k; char c; while(scanf("%d", &count) != EOF) { while(count--) { memset(a, 0, sizeof(char)*105); scanf("%d%d", &n, &m); getchar();
k = 0; for(i = 0; i < n; i++) { c = getchar(); /* 需选出m个数字, 已选中到第k个数字, 还有n-i个未遍历,若k+(n-i) > m, * 说明若后面有比前面选中数字大的,还需要替换掉, 此时选择替换掉小于c的数字 */ while(k > 0 && (i - k < (n - m)) && a[k] < c) k--; if (k < m) a[++k] = c; /* 若k<m,说明还没有选够m个数字 */ } a[++k] = '\0'; printf("%s\n", a + 1); } } return0; }