1 #include <iostream> 2 using namespace std; 3 const int MAX_N = 10000 + 8; 4 int S, N; 5 int T[MAX_N], F[MAX_N]; 6 int sum_F[MAX_N]; 7 int dp[MAX_N]; 8 int solve() 9 { 10 for (int j = N - 1; j >= 0; --j) 11 { 12 int f = sum_F[N] - sum_F[j], t = S; 13 for (int i = 1; j + i <= N && i <= 200; i++) 14 { 15 t += T[j + i - 1]; 16 dp[j] = min(dp[j], t * f + dp[j + i]); 17 } 18 } 19 return dp[0]; 20 } 21 int main() 22 { 23 #ifndef ONLINE_JUDGE 24 freopen("in.txt", "r", stdin); 25 #endif 26 scanf("%d%d", &N, &S); 27 memset(dp, 0x3f, N * sizeof(int)); 28 for (int i = 0; i < N; ++i) 29 { 30 scanf("%d%d", T + i, F + i); 31 sum_F[i + 1] = sum_F[i] + F[i]; 32 } 33 printf("%d ", solve()); 34 #ifndef ONLINE_JUDGE 35 fclose(stdin); 36 #endif 37 return 0; 38 }
http://www.hankcs.com/program/algorithm/poj-1180-batch-scheduling.html