Uvalive 6510 Stickers

Source: Internet
Author: User

This question did not write the problem at that time, this is a water DP bar
I'll give you a 2*n lattice, and then you can't take the next side of the stamp.
Then the current turntable can only be launched from the upper left and left corner of its own front, and finally the first and second rows to get the maximum value

#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;intdp[2][111111];inta[2][111111];intNintMain () {intTscanf("%d", &t); while(t--) {scanf("%d", &n); for(intj=0; j<=1; j + +) for(intI=1; i<=n;i++) {scanf("%d", &a[j][i]); }memset(DP,0,sizeof(DP)); dp[0][1]=a[0][1]; dp[1][1]=a[1][1]; a[0][0]=0; a[1][0]=0; for(intI=2; i<=n;i++) {dp[1][i]=max (dp[1][i],dp[0][i-1]+a[1][i]); dp[1][i]=max (dp[1][i],dp[0][i-2]+a[1][i]); dp[0][i]=max (dp[0][i],dp[1][i-1]+a[0][i]); dp[0][i]=max (dp[0][i],dp[1][i-2]+a[0][i]); }printf("%d\n", Max (dp[0][n],dp[1][n])); }}

Copyright notice: All brothers, please feel free to reprint, please indicate who is the brother

Uvalive 6510 Stickers

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.