【HDU1978】How many ways DP行走方式

来源:互联网 发布:淘宝活动招商入口 编辑:程序博客网 时间:2024/04/25 03:50

How many ways

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2736    Accepted Submission(s): 1613


Problem Description
这是一个简单的生存游戏,你控制一个机器人从一个棋盘的起始点(1,1)走到棋盘的终点(n,m)。游戏的规则描述如下:
1.机器人一开始在棋盘的起始点并有起始点所标有的能量。
2.机器人只能向右或者向下走,并且每走一步消耗一单位能量。
3.机器人不能在原地停留。
4.当机器人选择了一条可行路径后,当他走到这条路径的终点时,他将只有终点所标记的能量。

如上图,机器人一开始在(1,1)点,并拥有4单位能量,蓝色方块表示他所能到达的点,如果他在这次路径选择中选择的终点是(2,4)

点,当他到达(2,4)点时将拥有1单位的能量,并开始下一次路径选择,直到到达(6,6)点。
我们的问题是机器人有多少种方式从起点走到终点。这可能是一个很大的数,输出的结果对10000取模。
 

Input
第一行输入一个整数T,表示数据的组数。
对于每一组数据第一行输入两个整数n,m(1 <= n,m <= 100)。表示棋盘的大小。接下来输入n行,每行m个整数e(0 <= e < 20)。
 

Output
对于每一组数据输出方式总数对10000取模的结果.
 

Sample Input
16 64 5 6 6 4 32 2 3 1 7 21 1 4 6 2 75 8 4 3 9 57 6 6 2 1 53 1 1 3 7 2
 

Sample Output
3948
 

Author
xhd

#define DeBUG#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <string>#include <set>#include <sstream>#include <map>#include <list>#include <bitset>using namespace std ;#define zero {0}#define INF 0x3f3f3f3f#define EPS 1e-6#define TRUE true#define FALSE falsetypedef long long LL;const double PI = acos(-1.0);//#pragma comment(linker, "/STACK:102400000,102400000")inline int sgn(double x){    return fabs(x) < EPS ? 0 : (x < 0 ? -1 : 1);}#define N 155int mp[N][N];int main(){#ifdef DeBUGs    freopen("C:\\Users\\Sky\\Desktop\\1.in", "r", stdin);#endif    int T;    int n, m;    scanf("%d", &T);    while (T--)    {        scanf("%d%d", &n, &m);        memset(mp, 0, sizeof(mp));        mp[0][0] = 1;        for (int i = 0; i < n; i++)        {            for (int j = 0; j < m; j++)            {                int temp;                scanf("%d", &temp);                for (int k = 0; k <= temp; k++)                {                    for (int l = 0; l + k <= temp; l++)                    {                        if (k == 0 && l == 0)                            continue;                        mp[i + k][j + l] = (mp[i][j] + mp[i + k][j + l]) % 10000;                    }                }            }        }        printf("%d\n", mp[n - 1][m - 1]);    }    return 0;}


0 0
原创粉丝点击