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