[求助]
#include "stdio.h"#include "stdlib.h"
int times=0;
int Total_Num;
void OutTeam(Buffer,Num)
int *Buffer;
int Num;
{int i;
for (i=0;i<Num;i++)
printf("%3d",Buffer[i]);
printf("\n");
times++;
}
void MovePosition(Position,DesNum,Buffer)
int Position,DesNum;
int *Buffer;
{Buffer[Position]=DesNum;
OutTeam(Buffer,Position+1);
}
void SubAssign(Buffer,Position,Orig_Value,DesValue,Standard)
int *Buffer;
int Position,Orig_Value,DesValue,Standard;
{
if ((Position==Standard-1)&&(Orig_Value<=DesValue))
{MovePosition(Position,Orig_Value,Buffer);
SubAssign(Buffer,Position,++Orig_Value,DesValue,Standard);
}
else
{
while(Orig_Value<=DesValue)
{Buffer[Position]=Orig_Value;
SubAssign(Buffer,Position+1,Buffer[Position]+1,Total_Num-(Standard-1-(Position+1)),Standard);
Orig_Value++;
}
}
}
#define M 3
#define N 9
void main(void)
{int i,j,s,m,k,i1,i2,i3;
float f[N],max,sum1,sum2,sum3,a[M][2],b[N][2],c[N][2],d[N][2];
int Standard;
int *Buffer;
int OrigPosition=0;
printf("input numbers:\n");
{printf("input f[i]:\n");
for(i=0;i<N;i++)
scanf("%f",&f[i]);
printf("input a[i][j]:\n");
for(i=0;i<M;i++)
for(j=0;j<2;j++)
scanf("%f",&a[i][j]);
printf("input b[i][j]:\n");
for(i=0;i<N;i++)
for(j=0;j<2;j++)
scanf("%f",&b[i][j]);
printf("input c[i][j]:\n");
for(i=0;i<N;i++)
for(j=0;j<2;j++)
scanf("%f",&c[i][j]);
printf("input d[i][j]:\n");
for(i=0;i<N;i++)
for(j=0;j<2;j++)
scanf("%f",&d[i][j]);
sum1=0;sum2=0;sum3=0;
for(i=0;i<N;)
{sum1=sum1+b[i][1];sum2=sum2+c[i][1];sum3=sum3+d[i][1];
if(sum1>=a[0][1]&sum2>=a[1][1]&sum3>=a[2][1]) break;
else i++;
s=i;}
printf("s=%d",s);
printf("\n%f",f[s]);
while(j<N)
if(f[j]<f[s]) break;
else j++;
printf("\nj=%d",j);
Total_Num=j;
printf("\nTotal_Num=%d", Total_Num);
for(k=1;k<j;k++)
for(i=0;i<j-k;i++)
if(b[i][1]<=b[i+1][1])
{max=b[i][1];b[i][1]=b[i+1][1];b[i+1][1]=max;}
sum1=0;
for(i=0;i<j;)
{sum1=sum1+b[i][1];
if(sum1>=a[0][1]) break;
else i++;
i1=i+1;}
printf("\ni1=%d ",i1);
for(k=1;k<j;k++)
for(i=0;i<j-k;i++)
if(c[i][1]<=c[i+1][1])
{max=c[i][1];c[i][1]=c[i+1][1];c[i+1][1]=max;}
sum2=0;
for(i=0;i<j;)
{sum2=sum2+c[i][1];
if(sum2>=a[1][1]) break;
else i++;
i2=i+1;}
printf("\ni2=%d ",i2);
for(k=1;k<j;k++)
for(i=0;i<j-k;i++)
if(d[i][1]<=d[i+1][1])
{max=d[i][1];d[i][1]=d[i+1][1];d[i+1][1]=max;}
sum3=0;
for(i=0;i<j;)
{sum3=sum3+d[i][1];
if(sum3>=a[2][1]) break;
else i++;
i3=i+1;}
printf("\ni3=%d ",i3);
max=i1;
if(max<i2) max=i2;
if(max<i3) max=i3;
Standard=max;
printf("\nStandard=%d",Standard);
printf("\n");
Buffer=calloc(Standard,sizeof(int));
for (i=0;i<Standard;i++)
Buffer[i]=i+1;
SubAssign(Buffer,OrigPosition,Buffer[OrigPosition],Total_Num-(Standard-1-OrigPosition),Standard);
free(Buffer);
fprintf(stderr,"\ttimes=%d",times);
}
}
输出不小于f(s)的数目Total_Num(=j),从中选出Standard(=max)的全部组合,然后判断是否符合要求.(假设输出的一个组合是1 2 3 4,如果b[0][1]+...+b[3][1]>a[0][1],c[0][1]+...+c[3][1]>a[1][1],d[0][1]+...+d[3][1]>a[2][1]同时成立,则输出1 2 3 4,否则继续循环.
请各位指点迷津