那些题还不错,建议房主把那些帖子粘贴过来!大家可以讨论讨论!你是杭州电子科技大学的么?
回复 31楼 zglieren303
不是 不过我们都在做杭电的题目,大家可以都去做啊 一起学习啊
#include <cstdio> #include <algorithm> using namespace std; const int INF = 1000000000; const int MAX_N = 20; int dp[MAX_N][MAX_N]; int a[MAX_N], b[MAX_N], c[MAX_N]; int main() { int n; while (scanf("%d", &n), n) { int h, s, f; scanf("%d%d%d", &h, &s, &f); for (int i = 1; i <= n; ++i) { scanf("%d", a + i); b[i] = a[i]; } sort(b + 1, b + n + 1); int maxi = 0; for (int i = 1; i <= n; ++i) { c[i] = lower_bound(b + 1, b + n + 1, a[i]) - b; maxi = max(maxi, c[i]); } for (int i = 0; i <= n; ++i) for (int j = 0; j <= maxi; ++j) dp[i][j] = INF; dp[0][0] = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= maxi; ++j) { if (a[j] < a[i]) continue; for (int k = 1; k <= maxi; ++k) { int w; if (a[j] < a[k]) w = (a[k] - a[j]) * f; else if (a[j] == a[k]) w = 0; else w = (a[j] - a[k]) * h; w += a[j] * s; dp[i][j] = min(dp[i][j], dp[i - 1][k] + w); } } } int ret = INF; for (int j = c[n]; j <= maxi; ++j) ret = min(ret, dp[n][j]); printf("%d\n", ret); } return 0; }