Codeforces 467c George and job DP

Source: Internet
Author: User

N numbers are arranged in a column. In the N number, the K-segment continuous length is m and the sequence is maximized.

DP [I] [J] indicates that the maximum value of the J segment is obtained from the number of the first I segments.

# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; typedef long ll; ll DP [5100] [5100], sum [5100]; int n, m, K; int main () {scanf ("% d", & N, & M, & K); int I, j, X; sum [0] = 0; for (I = 1; I <= N; I ++) {scanf ("% d", & X ); sum [I] = sum [I-1] + X;} memset (DP, 0, sizeof (DP); for (I = m; I <= N; I ++) for (j = 1; j <= K; j ++) DP [I] [J] = max (DP [I-1] [J], DP [I-m] [J-1] + sum [I]-sum [I-m]); printf ("% i64d \ n ", DP [N] [k]); Return 0 ;}


Codeforces 467c George and job DP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.