Professional Documents
Culture Documents
Nakopia Salome-Quiz 1
Nakopia Salome-Quiz 1
n
is given natural number; (0.5 points)
a=1;
b=1;
for(i=3; i<n;i++)
c=a+b;
a=b;
b=c;
2. Write an algorithm which calculates the value of an expression:
S=1+1/x+1/x2+1/x3+…+1/xn
n is given natural number and x (x≠0) is given integer number; (0.5 points)
S[0]=1;
a[0]=1;
For (i=1;i<n;i++){
a[i]=a[i-1]/x;
S[i]=S[i-1]+a[i];
}
3. Write an algorithm (using a Dynamic Programming) which from the given matrix B with size NxM builds matrix C
with same size, an element C[i,j] of which is maximal from elements that lie in the left and upper side of the
position (i,j) (including) of the matrix B; (1 points)
B[0][0]=A[0][0];
for(j=1; j<m;j++)
B[0][j]=max(B[0][j-1],A[0][j]);
For (i=1;i<n;i++)
B[i][0]=max(B[i-1][0],A[i][0]);
for(i=1;i<n;i++)
for(j=1;j<m;j++){
B[i][j]=max(B[i][j-1],B[i-1][j])
B[i][j]=max(B[i][j],A[i][j]
}
0 1 0 1 0 1
1 1 1 1 1 0
1 1 1 1 0 1
1 1 1 1 1 0
1 0 1 1 1 1
You need to find a square block in this array with maximal size that consists of only 1’s; . Build the dynamic array
with the same size and fill it by solutions of subtasks. Find the size of the block that satisfies the conditions
described above; (0.5 points)