Untitled
unknown
plain_text
2 years ago
2.3 kB
7
Indexable
----------------------------------------DI CHUYEN BO-----------------------------------------------------------------------------
#include<iostream>
using namespace std;
int arr[1000];
int X[1000];
int w, n;
int ans;
void get_score(){
int temp = 0;
for(int i = 1; i<= n; i++){
if(X[i] == 1){
if(temp + arr[i] <= w){
temp += arr[i];
}
}
}
if(temp > ans) ans = temp;
}
void sinh(int k){
for(int i = 0; i <= 1; i++){
X[k] = i;
if(k == n){
get_score();
}
else sinh(k+1);
}
}
void reset(){
for(int i = 1; i <= n; i++){
X[i] = 0;
}
}
int main(){
freopen("input.txt", "r", stdin);
int T;
cin >> T;
for(int tc = 1; tc <= T; tc++){
cout << "#" << tc << " ";
cin >> w >> n;
reset();
for(int i = 1 ; i <= n; i++){
cin >> arr[i];
}
ans = 0;
sinh(1);
cout << ans << endl;
}
return 0;
}
-------------------------------------------------IN---------------------------------------------------------------------
20
372 5
133 111 144 103 130
314 5
130 131 114 133 125
398 5
111 139 100 128 147
331 5
137 149 139 148 124
840 6
118 120 147 120 124 143
786 8
132 137 128 132 109 134 133 144
889 5
117 123 108 136 127
572 5
105 118 117 107 106
1433 9
141 117 116 114 147 102 117 130 114
1246 8
102 114 100 139 133 113 143 105
1291 8
114 121 130 129 149 140 138 102
1033 10
107 110 105 116 145 133 148 100 126 126
1587 11
104 119 145 129 109 134 115 125 101 105 101
1783 11
147 101 140 142 111 127 127 122 125 111 119
1812 11
102 130 126 113 148 111 142 103 109 114 112
1616 12
149 103 122 130 135 143 138 115 113 131 117 144
1029 14
104 103 117 139 114 124 119 118 121 128 103 106 126 105
543 14
100 130 123 147 117 111 115 128 114 147 138 105 105 135
1348 14
144 120 143 105 125 137 135 143 102 126 147 144 103 147
1890 13
147 106 138 146 147 128 106 118 143 107 103 133 127
-------------------------------------------------------------------------OUT-------------------------------------------------------------------------
#1 366
#2 264
#3 397
#4 297
#5 772
#6 785
#7 611
#8 553
#9 1098
#10 949
#11 1023
#12 1011
#13 1287
#14 1372
#15 1310
#16 1540
#17 1029
#18 543
#19 1348
#20 1649Editor is loading...