标签:des style io os for 数据 div sp 问题
Description
Input
Output
Sample Input
1 2 2 10 5 1 1 2 2
Sample Output
14 思路:设dp[i][j]表示前i辆车还剩j个人的最小花费。那么我们需要去每次枚举减少的人#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <vector> using namespace std; const int maxn = 110; const int inf = 0x3f3f3f3f; int dp[maxn][maxn]; int n, k, s, d; int main() { int T; scanf("%d", &T); while (T--) { scanf("%d%d%d%d", &n, &k, &d, &s); for (int i = 0; i <= k; i++) for (int j = 0; j <= n; j++) dp[i][j] = inf; dp[0][n] = 0; int last = 0; for (int i = 1; i <= k; i++) { int t, p; scanf("%d%d", &t, &p); for (int j = n; j >= 0; j--) { if (dp[i-1][j] != inf) { dp[i][j] = min(dp[i][j], dp[i-1][j] + j * (t - last)); for (int l = 1; l <= p; l++) dp[i][j-l] = min(dp[i][j-l], dp[i-1][j] + j * (t - last) + d); } } last = t; } if (dp[k][0] == inf) printf("impossible\n"); else printf("%d\n", dp[k][0]); } return 0; }
标签:des style io os for 数据 div sp 问题
原文地址:http://blog.csdn.net/u011345136/article/details/39481731