int max(int a,int b){
if(a >= b){
return a;
}else{
return b;
}
}
void findCoin(int array[6][7], int row, int col){
int F[row + 1][col + 1];
for(int i = 0; i <= row; i++){
for(int j = 0; j <= col; j++){
F[i][j] = 0;
}
}
for(int i = 1; i <= row; i++){
for(int j = 1; j <= col; j++){
F[i][j] = max(F[i - 1][j], F[i][j - 1]) + array[i][j];
}
}
printf("最多可拾取%d枚硬币", F[row][col]);
}
int main () {
int row = 5, col = 6;
int array[6][7] = {
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0},
{0, 0, 1, 0, 1, 0, 0},
{0, 0, 0, 0, 1, 0, 1},
{0, 0, 0, 1, 0, 0, 1},
{0, 1, 0, 0, 0, 1, 0}};
printf("硬币分布为:\n");
for(int i = 1; i <= row; i++){
for(int j = 1; j <= col; j++){
printf("%d ", array[i][j]);
}
printf("\n");
}
findCoin(array, row, col);
return 0;
}