POJ 2385Apple catching (simple DP)

Source: Internet
Author: User

1 /*2 Test Instructions: There are two apple trees, each apple tree drops every second of an apple, a person under the tree to catch apples, do not let Apple fall! 3 The movement of people between the two trees is fast! But the number of people moving is limited, ask how many apples can be caught! 4     5 idea: Dp[i][j] represents the number of apples that have been caught in the case of J when the number of moves is the first I Apple drops! 6     7 so Dp[i][j]=max (Dp[i-1][j], dp[i][j-1]) + a[i]==j%2+1? 1:0;8     9 The a[i]==j%2+1 indicates that the first J-Move moves exactly under the a[i] apple tree, and this apple tree falls off the apple, just to catch! Ten */ One#include <iostream> A#include <cstring> -#include <cstdio> -#include <algorithm> the #defineM 1005 - using namespacestd; -  - intdp[m][ *]; +  - intN, M; + intA[m]; A  at intMain () { -scanf"%d%d", &n, &m); -     for(intI=1; i<=n; ++i) -scanf"%d", &a[i]); -    if(a[1]==1) dp[1][0]+=1; -     for(intI=2; i<=n; ++i) { indp[i][0]=dp[i-1][0]; -        if(a[i]==1) todp[i][0]+=1; +    } -        the     for(intj=1; j<=m; ++j) *        for(intI=j; i<=n; ++i) { $Dp[i][j]=max (dp[i][j-1], dp[i-1][j]);Panax Notoginseng            intcc=j%2+1; -            if(a[i]==cc) thedp[i][j]+=1; +       }  Aprintf"%d\n", Dp[n][m]); the    return 0; +}

POJ 2385Apple catching (simple 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: 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.