Describe
Digital triangles
Request to go to the last mod 100 max
Input format
Line 1th N, which represents n rows <=25
2nd to n+1 behavior each weight value
Output format
MoD 100 Maximum Value
Test Sample 1
Input
2
1
99 98
Output
99
Topic Analysis:
The digital triangle is a classic topic, so it has a lot of hardening versions. I made a 2--4. Although they are much the same, I still send it up so that we can expand our thinking. (In fact, my Code p,c interaction for a reason, because I started the summer vacation to C, at the same time began to brush the problem, so some questions are p, some of the problem is C)
So back to the chase. This problem I used a three-dimensional Boolean array f[i][j][k]. Using the idea of hash, directly save mod100 can arrive. The state transfer equation is very well written. The last enumeration of K is OK.
Source:
varI,j,k,n:longint; F:Array[0.. -,0.. -,0.. About] ofBoolean; A:Array[0.. -,0.. -] ofLongint;beginFillchar (F,sizeof (f), false); READLN (n); fori:=1 toN Do forj:=1 toI Doread (a[i,j]); f[1,1, a[1,1]MoD -]:=true; fori:=2 toN Do forj:=1 toI Do fork:=0 to About Do begin iff[i-1, J,k] ThenF[i,j, (K+a[i,j])MoD -]:=true; iff[i-1, J-1K ThenF[i,j, (K+a[i,j])MoD -]:=true; End; fori:= About Downto 0 Do forj:=1 toN Do ifF[n,j,i] Then beginWriteln (i); Exit End;End.
Back Gear | Digital Triangle 2