51nod 1293

递推

#include <bits/stdc++.h>

const int N = 1e3 + 10;

int A[N][N];
int n, m;
long long k, Sum[N][N][2];

inline long long read() {
    long long x; char c = getchar();
    while(c < '0' || c > '9') c = getchar();
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x;
}

int main() {
    std:: cin >> m >> n >> k;
    for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) std:: cin >> A[i][j];
    for(int i = 1; i <= n; i ++) {
        for(int j = 1; j <= m; j ++) {
            if(i == 1 && j == 1) {
                if(A[1][1] == 1) Sum[1][1][1] = (k + 1) >> 1, Sum[1][1][0] = k >> 1;
                else if(A[1][1] == -1) Sum[1][1][0] = (k + 1) >> 1, Sum[1][1][1] = k >> 1;
                else Sum[1][1][0] = k;
            } else {
                long long tmp = Sum[i - 1][j][0] + Sum[i][j - 1][1];
                if(!A[i][j]) Sum[i][j][0] = Sum[i - 1][j][0], Sum[i][j][1] = Sum[i][j - 1][1];
                else if(A[i][j] == 1) Sum[i][j][1] = (tmp + 1) >> 1, Sum[i][j][0] = tmp >> 1;
                else Sum[i][j][0] = (tmp + 1) >> 1, Sum[i][j][1] = tmp >> 1;
            }
        }
    }
    std:: cout << Sum[n][m][0];
    return 0;
}
/*
3 2 4
-1 0 -1
1 0 0
*/

 

posted @ 2018-07-02 18:10  qmey  阅读(155)  评论(0编辑  收藏  举报