Somme minimale (2)

Une grille carrée étant donnée, remplie d'entiers positifs, on souhaite traverser le carré avec une somme minimale des entiers rencontrés.

Pour cet exercice,

  • on souhaite aller du côté gauche au côté droit,
  • les seuls déplacements autorisés sont →, ↓, ↑
\[\begin{pmatrix} 131 & 673 & \mathbf{234} & \mathbf{103} & \mathbf{18} \\ \mathbf{201} & \mathbf{96} & \mathbf{342} & 965 & 150 \\ 630 & 803 & 746 & 422 & 111 \\ 537 & 699 & 497 & 121 & 956 \\ 805 & 732 & 524 & 37 & 331\\ \end{pmatrix}\]

Le chemin marqué en gras donne une somme de \(994\) qui est ici le minimum possible pour cet exercice.

Écrire une fonction telle que somme_minimale_2(grille) renvoie la somme minimale spécifiée plus haut. On garantit que la grille est carrée et remplie d'entiers positifs.

Exemples
\[\begin{pmatrix} 5 & 2 & 3 \\ \mathbf 2 & \mathbf 0 & 2 \\ 3 & \mathbf 2 & \mathbf 1 \\ \end{pmatrix}\]
🐍 Console Python
>>> grille = [[5, 2, 3], [2, 0, 5], [3, 2, 1],]
>>> somme_minimale_2(grille)
5
\[\begin{pmatrix} 9 & 9 & 0 & 9 & 9 \\ \mathbf{3} & \mathbf{1} & 9 & 9 & 9 \\ 5 & \mathbf{1} & 9 & \mathbf{1} & \mathbf{3} \\ 7 & \mathbf{1} & 9 & \mathbf{1} & 9\\ 9 & \mathbf{1} & \mathbf{1} & \mathbf{1} & 9\\ \end{pmatrix}\]
🐍 Console Python
>>> grille = [
...     [9, 9, 0, 9, 9],
...     [3, 1, 9, 9, 9],
...     [5, 1, 9, 1, 3],
...     [7, 1, 9, 1, 9],
...     [9, 1, 1, 1, 9],
... ]
>>> somme_minimale_2(grille)
14
\[\begin{pmatrix} 131 & 673 & \mathbf{234} & \mathbf{103} & \mathbf{18} \\ \mathbf{201} & \mathbf{96} & \mathbf{342} & 965 & 150 \\ 630 & 803 & 746 & 422 & 111 \\ 537 & 699 & 497 & 121 & 956 \\ 805 & 732 & 524 & 37 & 331\\ \end{pmatrix}\]
🐍 Console Python
>>> grille = [
...     [131, 673, 234, 103, 18],
...     [201, 96, 342, 965, 150],
...     [630, 803, 746, 422, 111],
...     [537, 699, 497, 121, 956],
...     [805, 732, 524, 37, 331],
... ]
>>> somme_minimale_2(grille)
994
###(Dés-)Active le code après la ligne # Tests (insensible à la casse)
(Ctrl+I)
Entrer ou sortir du mode "deux colonnes"
(Alt+: ; Ctrl pour inverser les colonnes)
Entrer ou sortir du mode "plein écran"
(Esc)
Tronquer ou non le feedback dans les terminaux (sortie standard & stacktrace / relancer le code pour appliquer)
Si activé, le texte copié dans le terminal est joint sur une seule ligne avant d'être copié dans le presse-papier
Évaluations restantes : 10/10
.128013o,5ym]vcf-pb0)42nulht3 kdwjSr6/7gs9e(aP[+:_8=1i050z0K0v0M0V0t0I0x0i0t0M0I0I0T010v0V0l010406050I0s0f0f0M0D0e040C0b0t0s0:0b0r050F0`0|0~100^0l04191g051j0F1j1l1g0^0z0V0h0(0*0,0.0u0V0H0u0t1z0u0v0?050Z0m0t0K1u0+0-011y1A1C1A0v1I1K1G0v0m0b0z101H0D1h0v0u0(130I0l0M0r0.0q011M1w010j0#0K0r0M0f0K1G1.1:1^1O1{1K1~200?0a0x0N0D0b0l0b0I0V160r0x0X1,0D0D0K0i2l19230r1h0F1*2y0v1(1%1)0z250.1C0r1}2i1G1r1t0)1N2I0V2K0r1!1s1G0l2r1h2w2y2$0_1/2m2Q1_2V0D0}0t0?0x0U2v2*0@2)242,1O2.2:2=0q2^1:2`2w2H012 0M2;040x0w332x0^362}0.393b0x0p3f352*373l2=0d3p3h3r3j380b2/3a2=0E3w2{2+1v2~3B303c0G3G3i3J3k3L3D3c0S3P3y3R3A3C3m0J3X2|3Z3t040U0n3p1i2!192O2B0z2F370i1!211h3?1k3;2(1a2_053{0X2#3Y2R010y0?0X0j3/3Q4a0A2=4g492-0j0?0I0b0|0K0R0f2T0V2:4t3243343H370=040L4l3)4a0r0?0H0D0#1K4I3I4a4F0o0Q3w0x4Y0x4D3z4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