Pagini recente » Cod sursa (job #1831584) | Cod sursa (job #2240662) | Cod sursa (job #1509216) | Cod sursa (job #875668) | Cod sursa (job #1676338)
#include<fstream>
#define DIM 132000
using namespace std;
int n, i, j, g, x, y, t;
int d[DIM], e[DIM], v[20];
ifstream fin("zebughil.in");
ofstream fout("zebughil.out");
int main(){
for(t = 3; t; t--){
fin>> n >> g;
for(i = 0; i < n; i++){
fin>> v[i];
}
for(i = 1; i < (1 << n); i++){
d[i] = 1000;
e[i] = 0;
for(j = 0; j < n; j++){
if( ( (i >> j) & 1) == 1 ){
if(e[i - (1 << j)] >= v[j]){
x = d[i - (1 << j)];
y = e[i - (1 << j)] - v[j];
}
else{
x = d[i - (1 << j)] + 1;
y = g - v[j];
}
if(x < d[i]){
d[i] = x;
e[i] = y;
}
else{
if(x == d[i] && y > e[i]){
e[i] = y;
}
}
}
}
}
fout<< d[ (1 << n) - 1] <<"\n";
}
return 0;
}