Pagini recente » Cod sursa (job #985789) | Cod sursa (job #2715747) | Cod sursa (job #1661896) | Cod sursa (job #394748) | Cod sursa (job #1104695)
#include <iostream>
#include <fstream>
#include <cstring>
#define DN (1<<17) + 13
using namespace std;
int g[20];
long long max_capacity[DN];
int dp[DN];
/// max_capacity [ st ] = cat e ocupat din ultimul camion daca am transportat deja toti bitii din stare
/// dp[ st ] = nr minim de camioane
int main()
{
int t = 3;
ifstream f("zebughil.in");
ofstream gg("zebughil.out");
for(;t--;){
memset(dp,127,sizeof(dp));
memset(max_capacity,0,sizeof(max_capacity));
int n,G,rez=22;
f>>n>>G;
for(int i=0;i<n;++i)
f>>g[i];
dp[0]=1;
for(int st = 0; st < (1<<n) ; ++st ){ /// am rezolvat toate pietrele din stare
for(int i=0;i<n;++i){ /// vin cu o piatra noua
if( ((st<<i)&1) == 0 ){ /// nu am transportat piatra i
int next_st = ( st|( 1<<i ) );
if( dp[st] + ( G < max_capacity[ st ] + g[ i ] ) <= dp[next_st] )
if( G < max_capacity[ st ] + g[ i ] ){
max_capacity[ next_st ] = g[i];
dp[ next_st ] = dp[ st ] +1;
}
else{
max_capacity[ next_st ] = max_capacity[ st ] + g[i];
dp[ next_st ] = dp[st];
}
//cout<<"Stare :" <<next_st<<" -> "<< max_capacity[next_st]<<" nr de camioane:"<<dp[next_st]<<"\n";
}
}
}
gg<<dp[ (1<<n) - 1 ]<<"\n";
}
return 0;
}