Pagini recente » Cod sursa (job #1270675) | Cod sursa (job #1668102) | Cod sursa (job #2339168) | Cod sursa (job #1500627) | Cod sursa (job #2798928)
#include <bits/stdc++.h>
using namespace std;
ifstream f("ghiozdan.in");
ofstream g("ghiozdan.out");
int frec[10000],n,gh,x,solutie[25000],dp[201],k;
int main()
{
f>>n>>gh;
for(int i=1; i<=n; i++)
{
f>>x;
frec[x]++;
}
dp[0]=1;
for(int i=200; i>=1; i--)
{
for(int j=gh; j>=0; j--)
{
if(dp[j])
{
for(k=1; k*i+j<=gh&&k<=frec[i]; k++)
{
if(dp[k*i+j])
{
break;
}
dp[k*i+j]=dp[j]+k;
solutie[i*k+j]=i;
}
}
}
}
while(!dp[gh])
gh=gh-1;
g<<gh<<" "<<dp[gh]-1<<" "<<endl;
while(gh)
{
g<<solutie[gh]<<endl;
gh=gh-solutie[gh];
}
}