tips:用递归的写法更加简单,易懂。
/***********************************************
** problem ID : zoj_3640.cpp
** create time : Thu Jul 23 20:57:26 2015
** auther name : xuelanghu
** auther blog : blog.csdn.net/xuelanghu407
**********************************************/
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n, f;
int c[110];
int t(int c) {
return (int ) ((1 + sqrt(5)) / 2 * c * c);
}
double DP (int f) {
double res = 0.0;
for (int i=0; i<n; i++) {
if (f > c[i]) {
res += t(c[i]);
} else {
res += (1 + DP(f + c[i]));
}
}
return res / n;
}
int main () {
while (cin >> n >> f) {
for (int i=0; i<n; i++) {
cin >> c[i];
}
printf ("%.3lf\n", DP(f));
}
return 0;
}版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/xuelanghu407/article/details/47128195