global n,m,matrix,pathmatrix
def rec(x, y):
try:
return pathmatrix[x,y]
except:
if x > 0:
left = rec(x - 1, y)
else:
left = (-1,[])
if y > 0:
up = rec(x, y - 1)
else:
up = (-1,[])
maxdist = max(left[0], up[0]) + matrix[x][y]
if left[0] > up[0]:
path = pathmatrix[x - 1,y][1].copy()
path.append('D')
else:
path = pathmatrix[x,y - 1][1].copy()
path.append('R')
pathmatrix[x,y] = (maxdist,path)
return pathmatrix[x,y]
n,m = [int(i) for i in input().split()]
matrix = [[int(i) for i in input().split()] for j in range(n)]
pathmatrix = {(0,0) : (matrix[0][0], [])}
res = rec(n-1,m-1)
print(res[0])
print(' '.join(res[1]))
global n,m,matrix,pathmatrix
def rec(x, y):
try:
return pathmatrix[x,y]
except:
if x > 0:
left = rec(x - 1, y)
else:
left = (-1,[])
if y > 0:
up = rec(x, y - 1)
else:
up = (-1,[])
maxdist = max(left[0], up[0]) + matrix[x][y]
if left[0] > up[0]:
path = pathmatrix[x - 1,y][1].copy()
path.append('D')
else:
path = pathmatrix[x,y - 1][1].copy()
path.append('R')
pathmatrix[x,y] = (maxdist,path)
return pathmatrix[x,y]
n,m = [int(i) for i in input().split()]
matrix = [[int(i) for i in input().split()] for j in range(n)]
pathmatrix = {(0,0) : (matrix[0][0], [])}
res = rec(n-1,m-1)
print(res[0])
print(' '.join(res[1]))
Объяснение:
Объяснение:
#include <iostream>
using namespace std;
int main()
{
int N, counter = 1, max_counter=1,post;
cin >> N;//всего матчей
cin >> post;// ввод первого числа последовательности
for (int i = 0; i < N-1; i++) {
int a;
cin >> a;// ввод остальных N-1 чисел последовательности
if (a == post && a == 1) {
counter++;
if (counter > max_counter)
max_counter = counter;
}
else
{
counter = 1;
}
post = a;
}
cout << max_counter;
return 0;
}
Паскаль?
program p1
var a,b,R,M,K:integer;
begin
readln(a,b)
R:=3*b
M:=6*a
K:=R+M
writeln(K)
end.