分析:假设存八年的次数是x8,则存五年的次数:(20-8*x8)/5,存三年的次数:(20-8*x8-5*x5)/3,存两年的次数:(20-8*x8-5*x5-3*x3)/2,存一年的次数:20-8*x8-5*x5-3*x3-2*x2.其中0<=x8<=2,0<=x5<=(20-8*x8)/5,0<=x3<=(20-8*x8-5*x5)/3,,0<=x2<=(20-8*x8-5*x5-3*x3)/2,x1=20-8*x8-5*x5-3*x3-2*x2,x1>=0.
#include<stdio.h>
#include<math.h>
int main()
{
double result,max=0;
int x8,x5,x3,x2,x1,y1,y2,y3,y5,y8;
for(x8=0;x8<=2;x8++)
{
for(x5=0;x5<=(20-8*x8)/5;x5++)
{
for(x3=0;x3<=(20-8*x8-5*x5)/3;x3++)
{
for(x2=0;x2<=(20-8*x8-5*x5-3*x3)/2;x2++)
{
x1=20-8*x8-5*x5-3*x3-2*x2;
result=2000*pow((1+0.0063*12),x1)*pow((1+2*0.0066*12),x2)*pow((1+3*0.0069*12),x3)*pow((1+5*0.0075*12),x5)*pow((1+8*0.0084*12),x8);
if(result>max)
{
max=result;
y1=x1;
y2=x2;
y3=x3;
y5=x5;
y8=x8;
}
}
}
}
}
printf("%lf\n",result);
printf("%d %d %d %d %d",y1,y2,y3,y5,y8);
return 0;
}
标签:pow,问题,x8,result,x2,x3,存钱,x5 From: https://www.cnblogs.com/qian-heng/p/17356285.html