codevs动态规划 老鼠的旅行
来源:互联网 发布:乌鲁木齐seo服务 编辑:程序博客网 时间:2024/04/30 04:15
You are a mouse that lives in a cage in a large laboratory.
你是一只生活在笼子里的实验室老鼠。
The laboratory is composed of one rectangular grid of square cages, with a total of R rows and C columns of cages (1 ≤ R,C ≤ 25).
实验室是一个R行C列的格子矩阵(1 ≤ R,C ≤ 25). 每个格子是一个笼子. (尼玛还要我活么……)
To get your exercise, the laboratory owners allow you to move between cages.
为了让你锻炼身体,实验室管理员允许你在笼子之间移动。
You can move between cages either by moving right between two adjacent cages in the same row, or by moving down between two adjacent cages in the same column.
你只能向右和向下移动。
You cannot move diagonally, left or up.
你不能斜着移动,也不能向上和向左移动。
Your cage is in one corner of the laboratory, which has the label (1,1) (to indicate top-most row, left-most column).
你所在的笼子是实验室的左上角,标记为(1,1)
You would like to visit your brother who lives in the cage labelled (R,C) (bottom-most row, right-most column), which is in the other corner diagonally.
你想去右下角的笼子(R,C)里找你的女朋友(尼玛老鼠也有女盆友么!!!)
However, there are some cages which you cannot pass through, since they contain cats.
但是有一些笼子是不能经过的,因为里面有猫(谁说老鼠怕猫么,还有,管理员有毛病么……)
Your brother, who loves numbers, would like to know how many different paths there are between your cage and his that do not pass through any cat cage. Write a program to compute this number of cat-free paths.
你女朋友很爱数学,她想要知道有多少条不同的路径可以从你的笼子到达她的笼子。写一个程序来计算吧。(这样的女朋友不要也罢……)
分析:这一题看上去很高大上,转化一下来想其实就是统计有几次可以走到(r,c),这么以来这题就很简单了。
动态转移方程:f[i,j]:=f[i-1.j]+f[i,j-1](这个点没有猫,更新时没必要判断来的点是否有猫,因为那个点的值一定是0,即没有路径可以走到那)
const
maxn=25;
var
map,f:array[0..maxn,0..maxn] of longint;
r,c,i,j,k,x,y:longint;
begin
readln(r,c);
readln(k);
for i:=1 to k do
begin
readln(x,y);
map[x,y]:=1;
end;
f[1,1]:=1;
for i:=1 to r do
for j:=1 to c do
begin
if (i=1) and (j=1) then continue;
if map[i,j]=0 then
f[i,j]:=f[i-1,j]+f[i,j-1];
end;
writeln(f[r,c]);
end.
- codevs动态规划 老鼠的旅行
- Codevs 1267老鼠的旅行
- Codevs 1267老鼠的旅行
- codevs 1267 老鼠的旅行 DP 解题报告
- 旅行商问题的动态规划解决
- codevs动态规划 选菜
- codevs动态规划
- HDU1009老鼠的旅行 (贪心算法)
- 基础贪心-nefuoj老鼠的旅行
- Codevs 3100 蜗牛的旅行
- codevs石子归并 动态规划
- codevs线段覆盖 动态规划
- codevs动态规划 能量项链
- codevs动态规划 数字游戏
- codevs动态规划 数字三角形
- TSP:旅行商问题与内存优化的动态规划
- codevs动态规划 金明的预算方案
- (昨晚的)codevs 旅行家的预算
- IAR的有用的快捷键
- 编程经验:关于OpenCV源码调试的好文章转载~
- 【3 月更新】React Native 优秀开源项目大全
- 【JavaScript】Javascript闭包
- 1265 四点共面(计算几何)
- codevs动态规划 老鼠的旅行
- curl post 接口测试
- PowerShell提取TFS更新记录中的文件列表
- Linux 常用命令总结
- 自定义计步--圆弧
- 如何使用Android Studio打包混淆的Jar
- MVP+RxJava+Retrofit_Okhttp框架优秀开源项目推荐
- jpa 分页
- js格式化input手机号