无聊做了下算法题,用递归方法,不知道对不对 int fun(int a[3][4],int n,int m,int i,int j) {     int key = a[i][j];     if(i +1 == n && j+1 == m) return key;     int right = key;     int down  = key;     if(j+1<m) right += fun(a,n,m,i,j+1);     if(i+1<n) down += fun(a,n,m,i+1,j);     return right>down?right:down; } int main() {     int a[3][4] = {      {2,5,6,4},      {5,8,7,3},      {9,5,1,4}     };     cout<<fun(a,3,4,0,0);     return 0; }
点赞 1

相关推荐

牛客网
牛客企业服务