Pagini recente » Cod sursa (job #2236577) | Cod sursa (job #1877319) | Cod sursa (job #2362586) | Cod sursa (job #2853588) | Cod sursa (job #2488747)
#include <bits/stdc++.h>
using namespace std;
ifstream f("zebughil.in");
ofstream g("zebughil.out");
const int Nmax = 20;
int v[Nmax];
int n, G;
const double eps = 0.275;
int solve(){
clock_t t = clock();
int ans = n, no, sum;
bool ok = true;
while(ok and (double)(clock() - t) / CLOCKS_PER_SEC <= eps){
sum = 0;
no = 1;
for(int i = 1; i <= n; ++i){
if(1LL * sum + 1LL * v[i] <= 1LL * G)
sum += v[i];
else{
sum = v[i];
++no;
}
}
ans = min(ans,no);
ok = next_permutation(v+1, v+n+1);
}
return ans;
}
int main(){
for(int t = 1; t <= 3; ++t){
f >> n >> G;
for(int i = 1; i <= n; ++i)
f >> v[i];
g << solve() << '\n';
}
return 0;
}