Var A:array[1..4] of integer; i,j,R,P:integer; function HOD(c,b:integer):integer; begin while c<>b do if c>b then c:=c-b else b:=b-c; HOD:=c; end; function HOK(c,b, RR:integer):integer; begin if ((c mod b=0) or (b mod c=0)) and ((c div b > 1) or (b div c > 1)) then begin if c>b then HoK:=c else HOK:=b; end else HOK:=(c*b) div RR; end; begin A[1]:=36; A[2]:=54; A[3]:=18; A[4]:=15; P:=1; R:=HOD(A[1],A[2]); P:=HOK(A[1], A[2], R); for i:=3 to 4 do begin R:=HOD(R, A[i]); P:=HOK(P, A[i],R); end; writeln('HOK = ',P); end.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int x, y;
cin >> x >> y;
vector<vector<int> > t(x, vector<int> (y));
for (int i = 0; i < x; ++i){
for (int j = 0; j < y; ++j){
int mark;
cin >> mark;
t[i][j] = mark;
}
}
for (int i = 1; i < y; ++i){
t[0][i] += t[0][i - 1];
}
for (int i = 1; i < x; ++i){
t[i][0] += t[i - 1][0];
}
for (int i = 1; i < x; ++i){
for (int j = 1; j < y; ++j){
t[i][j] += min(t[i - 1][j], t[i][j - 1]);
}
}
cout << t[x - 1][y - 1] << endl;
}
Объяснение: