# UVA 1336 Fixing the Great Wall

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <utility>
using namespace std;

#define rep(i,j,k) for (int i=j;i<=k;i++)
#define Rrep(i,j,k) for (int i=j;i>=k;i--)

#define Clean(x,y) memset(x,y,sizeof(x))
#define LL long long
#define ULL unsigned long long
#define inf 1000000001

const int maxn = 1009;

struct node
{
int pos;
int c;
}p[maxn];

int n,v,stpos,st;

double dp[maxn][maxn][2];
LL sum[maxn];

bool cmp( node x , node y )
{
return x.pos < y.pos;
}

void init()
{
n++;
p[n].pos = stpos;
sort( p + 1 , p + 1 + n , cmp );
Clean(sum,0);
rep(i,1,n)
}

double cal( int l , int r ) //计算除去[l,r]范围内的∑di
{
return sum[l-1] + sum[n] - sum[r];
}

double cost( int x1 , int x2 ) //两点之间需要用的时间
{
return (double)abs( p[x1].pos - p[x2].pos ) / (double)v;
}

void solve()
{
rep(i,1,n)
if ( p[i].pos == stpos )
{
st = i;
break;
}
rep(i,1,n)
if ( i == st ) dp[i][i][0] = dp[i][i][1] = 0;
else dp[i][i][0] = dp[i][i][1] = inf;
rep(len,1,n-1)
rep(l,1,n-len)
{
int r = l + len;
double ex = cal( l+1 , r );
dp[l][r][0] = min( dp[l+1][r][0] + ex * cost( l+1 , l ) , dp[l+1][r][1] + ex * cost( r , l ) );
ex = cal( l , r - 1 );
dp[l][r][1] = min( dp[l][r-1][0] + ex * cost( l , r ) , dp[l][r-1][1] + ex * cost( r - 1 , r ) );
}
double ans = min( dp[1][n][0] , dp[1][n][1] );
rep(i,1,n) ans += p[i].c;
printf("%d\n",(int)ans);
}

int main()
{
while(cin>>n>>v>>stpos)
{
if ( n + v + stpos == 0 ) break;
init();
solve();
}
return 0;
}


• 本文已收录于以下专栏：

举报原因： 您举报文章：UVA 1336 Fixing the Great Wall 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)