P1220 关路灯

#include <bits/stdc++.h>
using namespace std;
int d[100], w[100], s, n;
int dp[100][100][3];
int main() {
  scanf("%d%d", &n, &s);
  for (int i = 1; i <= n; i++)
    scanf("%d%d", &d[i], &w[i]), w[i] += w[i - 1];
  memset(dp, 0x3f, sizeof(dp));
  dp[s][s][0] = dp[s][s][1] = 0;
  for (int i = s; i >= 1; i--)
    for (int j = i + 1; j <= n; j++) {
      dp[i][j][0] =
          min(dp[i + 1][j][0] + (d[i + 1] - d[i]) * (w[n] - (w[j] - w[i])),
              dp[i][j][0]);
      dp[i][j][0] =
          min(dp[i + 1][j][1] + (d[j] - d[i]) * (w[n] - (w[j] - w[i])),
              dp[i][j][0]);
      dp[i][j][1] = min(dp[i][j - 1][1] +
                            (d[j] - d[j - 1]) * (w[n] - (w[j - 1] - w[i - 1])),
                        dp[i][j][1]);
      dp[i][j][1] =
          min(dp[i][j - 1][0] + (d[j] - d[i]) * (w[n] - (w[j - 1] - w[i - 1])),
              dp[i][j][1]);
    }
  printf("%d", min(dp[1][n][1], dp[1][n][0]));
}

posted on 2016-11-16 19:38  蒟蒻konjac  阅读(77)  评论(0编辑  收藏

统计