回答編集履歴
1
ソースを詳細に修正
test
CHANGED
@@ -10,35 +10,57 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
って
|
13
|
+
ちょっと修正して、1が3つあるとき、最大2円で6が返ってくるのを確認しました
|
14
14
|
|
15
|
-
|
15
|
+
```
|
16
16
|
|
17
|
-
|
17
|
+
#include <stdio.h>
|
18
|
+
|
19
|
+
struct Data{
|
20
|
+
|
21
|
+
float price;
|
22
|
+
|
23
|
+
};
|
18
24
|
|
19
25
|
|
20
26
|
|
21
|
-
|
27
|
+
int pick(Data *data, int index, int maxindex, float price, float maxprice){
|
22
28
|
|
23
|
-
|
29
|
+
int count = 0;
|
24
30
|
|
25
|
-
if (maxindex <= index) return;
|
31
|
+
if (maxindex <= index) return 0;
|
26
32
|
|
27
33
|
float newprice = price + data[index].price;
|
28
34
|
|
29
35
|
if (newprice <= maxprice){
|
30
36
|
|
31
|
-
(
|
37
|
+
(count)++;
|
32
38
|
|
33
39
|
// indexの商品を追加して次の工程に
|
34
40
|
|
35
|
-
pick(data, index + 1, maxindex, newprice, maxprice
|
41
|
+
count += pick(data, index + 1, maxindex, newprice, maxprice);
|
36
42
|
|
37
43
|
}
|
38
44
|
|
39
45
|
// indexの商品を追加せずに次の工程に
|
40
46
|
|
41
|
-
pick(data, index + 1, maxindex, price, maxprice
|
47
|
+
count += pick(data, index + 1, maxindex, price, maxprice);
|
48
|
+
|
49
|
+
return count;
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
int main(){
|
56
|
+
|
57
|
+
Data d[] = {{1}, {1}, {1}};
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
int count = pick(d, 0, 3, 0, 2);
|
62
|
+
|
63
|
+
printf("%d", count);
|
42
64
|
|
43
65
|
}
|
44
66
|
|