思路:
一维dp。
实现:
1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 const int INF = 0x3f3f3f3f; 5 int w[1005], v[1005], sum[1005]; 6 double dp[1005]; 7 int main() 8 { 9 int b, l, n; 10 while (cin >> b >> l >> n, b || l || n) 11 { 12 for (int i = 1; i <= n; i++) dp[i] = INF; 13 for (int i = 1; i <= n; i++) 14 { 15 cin >> w[i] >> v[i]; 16 sum[i] = sum[i - 1] + w[i]; 17 } 18 dp[1] = (double)l / v[1]; 19 for (int i = 2; i <= n; i++) 20 { 21 int minn = v[i]; 22 for (int j = i; j >= 1; j--) 23 { 24 if (sum[i] - sum[j - 1] > b) continue; 25 minn = min(minn, v[j]); 26 dp[i] = min(dp[i], dp[j - 1] + (double)l / minn); 27 } 28 } 29 printf("%.1f ", dp[n] * 60); 30 } 31 return 0; 32 }