一次格子取数的问题

#include <stdio.h>
#include <stdlib.h>

int geZiQuShu(int num[][4], int h, int l){
    int up, left;

    if(h < 0 || l < 0) return 0;
    if(h == 0 && l == 0) return num[0][0];
    up = geZiQuShu(num, h - 1, l);
    left = geZiQuShu(num, h, l - 1);
    if(up > left){
        return up + num[h][l];
    }
    else{
        return left + num[h][l];;
    }

}

main(){
    int num[4][4] = {20, 20, 20, 4, 5, 6, 20, 8, 9, 10, 20, 12, 13, 14, 20, 20};
    int result;
    result = geZiQuShu(num, 3, 3);
    printf("%d \n", result);
}

 

posted @ 2014-03-06 10:29  yutoulck  阅读(173)  评论(0编辑  收藏  举报