HDU 2845 Beans

Source: Internet
Author: User

Dp.

DP processes the maximum value each row can get, and then the DP chooses which lines to get the maximum value.

The essence of row and column selection is the same operation.

#include <cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;Const intmaxn=200000+Ten;intn,m;Long Longa[maxn],f[maxn],dp[maxn][2];Long LongB[MAXN];Long LongWorkintLen) {    Long Longres=0; dp[0][0]=dp[0][1]=0;  for(intI=1; i<=len;i++) {dp[i][0]=max (dp[i-1][1],dp[i-1][0]); dp[i][1]=dp[i-1][0]+B[i]; Res=max (Res,max (dp[i][0],dp[i][1])); }    returnRes;}intMain () { while(~SCANF ("%d%d",&n,&m)) { for(intI=1; i<=n*m; i++) scanf ("%lld",&A[i]); intCnt=0, hang=1;  for(intI=1; i<=n*m;i++) {b[++cnt]=A[i]; if(cnt==m) {F[hang++]=Work (m); CNT=0; }        }         for(intI=1; i<=n;i++) b[i]=F[i]; printf ("%lld\n", Work (n)); }    return 0;}

HDU 2845 Beans

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: info-contact@alibabacloud.com 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.