Pagini recente » Cod sursa (job #1137727) | Cod sursa (job #684466) | Cod sursa (job #1205991) | Cod sursa (job #1610058) | Cod sursa (job #284530)
Cod sursa(job #284530)
#include <stdio.h>
FILE *f= fopen("economie.in","r");
FILE *g= fopen("economie.out","w");
unsigned char ok[50040];
unsigned ax,n,a[1040],max,i,j,min[1040],k=0;
int main()
{
fscanf(f,"%d",&n);
for(i=1;i<=n;i++)
{
fscanf(f,"%d",&a[i]);
if(a[i]>max||i==1)
max=a[i];
}
// fprintf(f,"\n");
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
if(a[i]>a[j])
{
ax=a[i];
a[i]=a[j];
a[j]=ax;
}
ok[0]=1;
for(i=1;i<=n;i++)
{
if(ok[a[i]]==0)
min[++k]=a[i];
for(j=0;j<=max;j++)
if(ok[j]==1&&j+a[i]<=max)
ok[j+a[i]]=1;
}
fprintf(g,"%d\n",k);
for(i=1;i<=k;i++)
fprintf(g,"%d\n",min[i]);
return 0;
}