Hiho digital triangle in week 5

Source: Internet
Author: User

Hiho digital triangle in week 5

Question 1: Digital triangle

 

[Explanation]

The most basic dynamic planning, the prompt shows the basic conditions for using dynamic planning, I feel very good:

(1)No aftereffect: "No matter how I arrive at room j on the I-level, my previous choices will not impose restrictions or preferential treatment on my subsequent choices. Just like if IIt must be at least three times to the rightSo the status is not just (I, j, k), but also the number of times that has been shifted to the right. Do you think it can be calculated directly like our previous method? If you walk three times to the right on the way to room j at level I, there will be no restriction on the subsequent steps. Otherwise, there will still be a limit that should at least go to the right for a certain number of times ."

(2)Replay Problem: "We will break down the best path from the starting point to the maze into two sub-problems. The first is the best way to exit the maze from the second room on the fifth floor, the second is the best way to walk out of the maze from the second room on the fifth floor,You only need to calculate the optimal values of the two parts.I can know the best way from the starting point to getting out of the maze ." Xiao Hi said: "In this way, both sub-problems have the same sub-problem-the best way to get out of the maze from the 3rd rooms on the fifth floor .""

[Write details]

What's hard about DP?Border ProcessingPart, usually

(1)Best [0] [0]Processing separately,N = 1Processing separately;

(2) In this question, the leftmost column and rightmost oblique column of a triangle must be processed separately.

AC code]

 

#include
 
  #include
  
   #include
   
    int reward[101][101];long best[101][101];long max(long a, long b){if(a>b) return a;else return b;}int main(){int n;scanf(%d, &n);memset(reward, 0, sizeof(reward));memset(best, 0, sizeof(best));for(int i=0; i
    
     

 

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.