# 13701 - fruit sale >author: Utin ###### tags: `combination` --- ## Brief See the code below ## Solution 0 ```c= #include <stdio.h> int n; int weight[20], value[20]; int limit; void count(int index, int sum_w, int sum_v); int ans = 0; int main() { scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%d", &weight[i]); } for(int i = 0; i < n; i++) { scanf("%d", &value[i]); } scanf("%d", &limit); for(int i = 0; i < n; i++) { if(weight[i] <= limit) { count(i, 0, 0); } } printf("%d\n", ans); } void count(int index, int sum_w, int sum_v) { // 加總 sum_w += weight[index]; sum_v += value[index]; // 把最大值存起來 if(ans < sum_v) ans = sum_v; // 這是組合不是排列,從index+1開始往後找就好 for(int i = index + 1; i < n; i++) { if(sum_w + weight[i] <= limit) { count(i, sum_w, sum_v); } } } // By Utin ``` ## Reference