How many ways

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

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
1
6 6
4 5 6 6 4 3
2 2 3 1 7 2
1 1 4 6 2 7
5 8 4 3 9 5
7 6 6 2 1 5
3 1 1 3 7 2
 
Sample Output
3948
 #include<stdio.h>
#include<string.h>
int a[][],dp[][];
int main()
{
int T,n,m,i,j,t,p;
scanf("%d",&T);
while(T--)
{
memset(dp,,sizeof(dp));
dp[][] = ;
scanf("%d%d",&n,&m);
for(i = ;i < n;i ++)
{
for(j = ;j < m;j ++)
{
scanf("%d",&a[i][j]);
for(t = ;t <= a[i][j];t ++)
{
for(p = ;p <= a[i][j]-t;p ++)
{
if(t!=||p!=)
dp[i+t][j+p] = (dp[i+t][j+p]+dp[i][j])%;
}
}
}
}
printf("%d\n",dp[n-][m-]);
}
return ;
}

How many ways的更多相关文章

  1. [LeetCode] Different Ways to Add Parentheses 添加括号的不同方式

    Given a string of numbers and operators, return all possible results from computing all the differen ...

  2. [LeetCode] Decode Ways 解码方法

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...

  3. Decode Ways

    https://leetcode.com/problems/decode-ways/ A message containing letters from A-Z is being encoded to ...

  4. 【LeetCode】241. Different Ways to Add Parentheses

    Different Ways to Add Parentheses Given a string of numbers and operators, return all possible resul ...

  5. [Leetcode] Decode Ways

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...

  6. Three ways to set specific DeviceFamily XAML Views in UWP

    Three ways to set specific DeviceFamily XAML Views in UWP http://igrali.com/2015/08/02/three-ways-to ...

  7. 241. Different Ways to Add Parentheses

    241. Different Ways to Add Parentheses https://leetcode.com/problems/different-ways-to-add-parenthes ...

  8. Different Ways to Add Parentheses

    Given a string of numbers and operators, return all possible results from computing all the differen ...

  9. 【leetcode】Decode Ways(medium)

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...

  10. [LintCode] Decode Ways 解码方法

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...

随机推荐

  1. dapper的一个小扩展以支持dataset

    废话不多,直接上方法 public static DataSet ExecuteDataSet(this IDbConnection cnn, IDbDataAdapter adapter, stri ...

  2. What is the Xcopy Command?:

    Quote from: http://pcsupport.about.com/od/commandlinereference/p/xcopy-command.htm The xcopy command ...

  3. 九度OJ 1201 二叉排序树

    题目地址:http://ac.jobdu.com/problem.php?pid=1201 题目描述: 输入一系列整数,建立二叉排序数,并进行前序,中序,后序遍历. 输入: 输入第一行包括一个整数n( ...

  4. 完整的 AJAX 写法(支持多浏览器)

    代码如下: <script type="text/javascript"> var xmlhttp; function Submit() { //1.创建 XMLHtt ...

  5. ajax的访问 WebService 的方法

    如果想用ajax进行访问 首先在web.config里进行设置 添加在 <webServices> <protocols> <add name= "HttpPo ...

  6. Python编写的Linux网络设置脚本,Debian Wheezy上测试通过

    hon编写的Linux网络设置脚本,Debian Wheezy上测试通过       阿里百川梦想创业大赛,500万创投寻找最赞的APP 技术细节参见Linux网络设置高级指南 注意事项参见程序注释 ...

  7. 【C++】类型转换

    引言 C++风格的四种类型转换方法:static_cast.dynamic_cast.reinterpret_cast.const_cast. 欢迎来到 lovickie 的博客 http://www ...

  8. easy ui tree 取复选框打勾的值

    var nodes = $('#basetree').tree('getChecked'); var cnode = ''; for ( var i = 0; i < nodes.length; ...

  9. C# DES

    using System; //这个是使用DES的基础 using System.Security.Cryptography; //这个是处理文字编码的前提 using System.Text; // ...

  10. Python正则表达式Regular Expression基本用法

    资料来源:http://blog.csdn.net/whycadi/article/details/2011046   直接从网上资料转载过来,作为自己的参考.这个写的很清楚.先拿来看看. 1.正则表 ...