原题题目
代码实现(首刷自解)
int sumlove;
int cmp(const void* a,const void* b)
{
return *(int*)a - *(int*)b;
}
void calculate(int* satisfaction,int satisfactionSize,int pos,int temp,int times)
{
if(pos < satisfactionSize){
if((temp+=(satisfaction[pos]* times)) > sumlove)sumlove = temp;calculate(satisfaction,satisfactionSize,pos+1,temp,times+1);}
}int maxSatisfaction(int* satisfaction, int satisfactionSize){
sumlove = 0;int i;qsort(satisfaction,satisfactionSize,sizeof(int),cmp);for(i=0;i<satisfactionSize;i++)calculate(satisfaction,satisfactionSize,i,0,1);return sumlove;
}