#include <stdio.h>
#include <stdlib.h>
int qtdseq(int matriz[10][12], int lin, int col, int num) {
if (lin >= 10 || col >= 12 || lin < 0 || col < 0) return 0;
if (matriz[lin][col] != num) return 0;
if (num == 1) return 1;
return qtdseq(matriz, lin, col + 1, num - 1)
+ qtdseq(matriz, lin, col - 1, num - 1)
+ qtdseq(matriz, lin + 1, col, num - 1)
+ qtdseq(matriz, lin - 1, col, num - 1);
}
int main() {
int mat[10][12] = {
{34, 45, 18, 56, 98, 33, 42, 67, 6, 11, 40, 10},
{88, 59, 23, 34, 44, 11, 34, 61, 43, 1, 3, 9},
{33, 32, 31, 22, 33, 77, 12, 11, 34, 98, 72, 74},
{40, 50, 21, 17, 15, 52, 45, 10, 9, 32, 27, 30},
{ 4, 14, 32, 11, 22, 33, 44, 65, 8, 52, 76, 12},
{ 6, 13, 56, 91, 22, 45, 22, 18, 7, 45, 23, 44},
{ 8, 9, 20, 87, 2, 5, 56, 5, 6, 5, 4, 3},
{12, 99, 23, 4, 3, 81, 42, 4, 8, 4, 77, 2},
{98, 97, 96, 95, 38, 1, 2, 3, 56, 3, 56, 1},
{ 3, 1, 7, 45, 93, 96, 1, 46, 1, 2, 41, 23}
};
printf("Quantidade de sequĂȘncias encontradas = %d\n", qtdseq
(mat
, 2, 6, 12)); }
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCmludCBxdGRzZXEoaW50IG1hdHJpelsxMF1bMTJdLCBpbnQgbGluLCBpbnQgY29sLCBpbnQgbnVtKSB7CiAgICBpZiAobGluID49IDEwIHx8IGNvbCA+PSAxMiB8fCBsaW4gPCAwIHx8IGNvbCA8IDApIHJldHVybiAwOwogICAgaWYgKG1hdHJpeltsaW5dW2NvbF0gIT0gbnVtKSByZXR1cm4gMDsKICAgIGlmIChudW0gPT0gMSkgcmV0dXJuIDE7CgogICAgcmV0dXJuIHF0ZHNlcShtYXRyaXosIGxpbiwgICAgIGNvbCArIDEsIG51bSAtIDEpC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