HDOJ-1978 How many ways

来源:互联网 发布:精通shell编程 知乎 编辑:程序博客网 时间:2024/06/05 11:58

注意:选择一个终点代表了一种路径选择

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <vector>using namespace std;int dp[105][105];int main(){    //freopen("in.txt", "r", stdin);    int t;    cin >> t;    while(t--)    {        memset(dp, 0, sizeof(dp));        int n, m;        cin >> n >> m;        dp[0][0] = 1;        for(int i = 0; i < n; i++)            for(int j = 0; j < m; j++)        {            int p;            cin >> p;            for(int h1 = 0; h1 <= p; h1++)            {                for(int h2 = 0; h2 <= p - h1; h2++)                {                    if(h1 == 0 && h2 == 0)                        continue;                    int s1 = i + h1;                    int s2 = j + h2;                    if(s1 < n && s2 < m)                    {                       dp[s1][s2] = (dp[i][j] + dp[s1][s2]) % 10000;                    }                }            }        }        cout << dp[n-1][m-1] << endl;    }    return 0;}
0 0