Pagini recente » Cod sursa (job #1188975) | Cod sursa (job #1496809) | Cod sursa (job #2952419) | Cod sursa (job #3193771) | Cod sursa (job #2798925)
#include <bits/stdc++.h>
using namespace std;
ifstream f("ghiozdan.in");
ofstream g("ghiozdan.out");
int frec[201],n,gh,x,solutie[1000],dp[100],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];
}
}