sicily 1264. Atomic Car Race 动态规划

//这题做了一晚

//很简单的dp水题,一开始超时,优化后又WA,结果发现是输出精度不够,至少要输出小数点后4位

//先要预处理一下,不然dp过程中会出现很多重复计算

//设dp[i]为完成路程a[1]+...+a[i]的最小时间,cost[i][j]为从站i换轮胎后,到站j所需的时间

//dp[i] = min(dp[k]+cost[k][i]+b), 0 < k < i

//dp[0] = 0;

#include <iostream>

#include <cstdio>

using namespace std;



const int N = 105;

const int M = 10005;



const int INF = 1000000000;



double dp[N];

double cost[N][N];

double total[M];



int record[N];

int a[N];

int n, r;

double v,e,f,b;



double cal(int x)

{

	if (x >= r)

		return 1/(v- e*(x-r));

	else

		return 1/(v - f*(r-x));

}



int main()

{

	a[0] = 0;

	int maxx, mini;



	while (cin >> n && n)

	{

		maxx = -INF;

		for (int i = 1; i <= n; i++)

		{

			cin >> a[i];

			dp[i] = INF;

			maxx = max(maxx, a[i]);

		}

		cin >> b;

		cin >> r >> v >> e >> f;



		total[0] = cal(0);

		for (int i = 1; i <= maxx; i++)

			total[i] = total[i-1] + cal(i);	

		

		for (int i = 0; i <= n; i++)

			for (int j = i+1; j <= n; j++)

				cost[i][j] = total[a[j]-a[i]-1];		

			

		dp[0] = 0;

		record[0] = 0;

		for (int i = 1; i <= n; i++)

			for (int k = 0; k < i; k++)		

				if (k != 0)

					dp[i] = min(dp[i], dp[k]+cost[k][i]+b);

				else

					dp[i] = min(dp[i], dp[k]+cost[k][i]);		

		

		printf("%.4lf\n", dp[n]);		

	}

	return 0;

}

你可能感兴趣的:(atomic)