hdoj1244_Max Sum Plus Plus Plus(dp)

【hdoj1244_Max Sum Plus Plus Plus(dp)】题目中先后的意思是顺序前后的意思

#include #include #includeusing namespace std; long long num[10100], len[100], table[10100][100], sum[10100]; long long dp(int n,int m) { memset(table, 0, sizeof(table)); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { table[i][j] = table[i - 1][j]; if (i >= len[j]) { table[i][j] = max(table[i][j], table[i - len[j]][j - 1] + sum[i] - sum[i - len[j]]); } } return table[n][m]; }int main() { int n; while (cin >> n&&n) { int m; cin >> m; for (int i = 1; i <= m; i++) cin >> len[i]; sum[0] = 0; for (int i = 1; i <= n; i++) { cin >> num[i]; sum[i] = sum[i - 1] + num[i]; } cout << dp(n, m) << endl; } return 0; }

    推荐阅读