Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
149167 曾煦翔 切割铜棒 C++ 通过 100 0 MS 268 KB 699 2024-05-25 17:03:05

Tests(5/5):


#include <bits/stdc++.h> using namespace std; int cut[55], dp[55][55]; int main(){ int L, N; while (cin >> L >> N) { for (int i = 1; i <= N; ++i) cin >> cut[i]; cut[0] = 0; cut[N + 1] = L; memset(dp, 127 / 2, sizeof(dp)); for (int i = 0; i <= N; ++i) dp[i][i + 1] = 0; for (int i = 2; i <= N + 1; ++i) for (int s = 0; s + i <= N + 1; ++s) for (int k = s + 1; k < s + i; ++k) dp[s][s + i] = min(dp[s][s + i], dp[s][k] + dp[k][s + i] + cut[s + i] - cut[s]); cout << "The minimum cutting is " << dp[0][N + 1] << "." << endl; } return 0; }


测评信息: