空间限制: 128000 KB
 题目等级 : 黄金 Gold
 查看运行结果
 
 
题目描述 Description

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.

你女朋友很爱数学,她想要知道有多少条不同的路径可以从你的笼子到达她的笼子。写一个程序来计算吧。(这样的女朋友不要也罢……)

输入描述 Input Description

The first line of input contains two integers R and C, separated by one space representing the number of rows and columns (respectively). On the second line of input is the integer K, the number of cages that contain cats. The next K lines each contain the row and column positions (in that order) for a cage that contains a cat. None of the K cat cages are repeated, and all cages are valid positions. Note also that (1,1) and (R,C) will not be cat cages.

第一行包含2个整数R和C,第二行一个整数K,代表包含猫的笼子的个数,接下来K行包含K个不同的位置信息,代表K个包含猫的笼子的位置信息,注意(1,1)和(R,C)这两个位置是不会有猫的, 否则出题者就没法活了……

输出描述 Output Description

Output the non-negative integer value representing the number of paths between your cage at position (1,1) and your brother’s cage at position (R,C). You can assume the output will be strictly less than 1 000 000 000.

输出一个非负整数代表你可以去你女朋友笼子里和她啪啪啪的路径数目,你可以假设这个输出会严格小于1,000,000,000。

样例输入 Sample Input

样例输入 1:

2 3

1

2 1

样例输入 2:

3 4

3

2 3

2 1

1 4

样例输出 Sample Output

样例输出 1: 2

样例输出 2: 1

数据范围及提示 Data Size & Hint
 

分类标签 Tags 点此展开

 
 
 #include <algorithm>
#include <cstdio> using namespace std; int r,c,k,ans,x,y;
int map[][];
int fx[]={,};
int fy[]={,}; void DFS(int x,int y)
{
if(x==r&&y==c)
{
ans++;
return ;
}
for(int i=;i<;i++)
{
int xx=x+fx[i],yy=y+fy[i];
if(!map[xx][yy]&&xx<=r&&yy<=c&&xx>&&yy>)
{
map[xx][yy]++;
DFS(xx,yy);
map[xx][yy]--;
}
}
} int main()
{
scanf("%d%d%d",&r,&c,&k);
for(int i=;i<=k;i++)
{
scanf("%d%d",&x,&y);
map[x][y]=;
}
map[][]++;
DFS(,);
printf("%d",ans);
return ;
}

TLE了一个点的DFS~~

正解棋盘DP

 #include <algorithm>
#include <cstdio> using namespace std; int r,c,k,ans,x,y;
int map[][],f[][]; int main()
{
scanf("%d%d%d",&r,&c,&k);
for(int i=;i<=k;i++)
{
scanf("%d%d",&x,&y);
map[x][y]=;
}
f[][]=;//从(1,1)走,开始最少有一个方案
for(int i=;i<=r;i++)
for(int j=;j<=c;j++)
{
if(map[i][j]) f[i][j]=;
else f[i][j]+=f[i-][j]+f[i][j-];
}
printf("%d",f[r][c]);
return ;
}

codevs——T1267 老鼠的旅行的更多相关文章

  1. codevs——1267 老鼠的旅行(棋盘DP)

    1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description ...

  2. codevs 1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛

    时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题目描述 Description You are a mouse that lives in a cage in ...

  3. dp练习(2)——老鼠的旅行

    1267 老鼠的旅行(来源:codevs) #include "bits/stdc++.h" using namespace std; ][]; ][]; int main() { ...

  4. 1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛

    1267 老鼠的旅行  2012年CCC加拿大高中生信息学奥赛 题目描述 Description You are a mouse that lives in a cage in a large lab ...

  5. CODEVS——T 1036 商务旅行

    http://codevs.cn/problem/1036/  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Descript ...

  6. codevs 1450 xth 的旅行

     时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 毕业了,Xth很高兴,因为他要和他的 ra ...

  7. codevs 1405 牛的旅行x

    牛的旅行 [问题描述] 农民John的农场里有很多牧区.有的路径连接一些特定的牧区.一片所有连通的牧区称为一个牧场.但是就目前而言,你能看到至少有两个牧场不连通.现在,John想在农场里添加一条路径 ...

  8. HDU1009老鼠的旅行 (贪心算法)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. DP(第一版)

    序 任何一种具有递推或者递归形式的计算过程,都叫做动态规划 如果你一开始学的时候就不会DP,那么你在考试的时候就一定不会想到用动态规划! 需要进行掌握的内容 1)DP中的基本概念 2)状态 3)转移方 ...

随机推荐

  1. tensorflow 模型压缩

    模型压缩 为了将tensorflow深度学习模型部署到移动/嵌入式设备上,我们应该致力于减少模型的内存占用,缩短推断时间,减少耗电.有几种方法可以实现这些要求,如量化.权重剪枝或将大模型提炼成小模型. ...

  2. 云-阿里云-OSS:对象存储 OSS

    ylbtech-云-阿里云-OSS:对象存储 OSS 对象存储服务(Object Storage Service,OSS)是一种海量.安全.低成本.高可靠的云存储服务,适合存放任意类型的文件.容量和处 ...

  3. 88. [ExtJS2.1教程-5]ToolBar(工具栏)

    转自:https://llying.iteye.com/blog/324681 面板中可以有工具栏,工具栏可以位于面板顶部或底部,Ext中工具栏是由Ext.Toolbar类来表示.工具栏上可以放按钮. ...

  4. Oracle占用内存过高解决办法

    1.cmd sqlplus system账户登录 2.show parameter sga; --显示内存分配情况 3.alter system set sga_max_size=200m scope ...

  5. 自定义View(6)paint设置两个图层相交时的显示方式,包含清空canvas

    1.问题 在已有的图层上绘图将会在其上面添加一层新的图层. 如果新的图层是完全不透明的,那么它将完全遮挡住下面的图层,而setXfermode就可以来解决这个问题.这个函数设置两个图层相交时的模式 . ...

  6. MyEclipse中快速复制粘贴当前行的操作

  7. html中canvas渲染图片,并转化成base64格式保存

    最近在做一个上传头像然后保存显示的功能,因为涉及到裁剪大小和尺寸比例,所以直接上传图片再展示的话,就会出现问题,所以就想用canvas来渲染裁剪后的图片,然后转化成base64格式的图片再存储,这样取 ...

  8. TypeError: Object function (req, res, next) { app.handle(req, res, next); } has no method 'configure'

    TypeError: Object function (req, res, next) { app.handle(req, res, next); } has no method 'configure ...

  9. 详细解读css中的浮动以及清除浮动的方法

    对于前端初学者来说,css浮动部分的知识是一块比较难以理解的部分,下面我将把我学习过程中的心得分享给大家. 导读:   1.css块级元素讲解 2.css中浮动是如何产生的 3.出现浮动后,如何清除浮 ...

  10. 前端面试基础-html篇之H5新特性

    h5的新特性(目前个人所了解)如下 语义化标签 表单新特性 视频(video)和音频(audio) canvas画布 svg绘图 地理定位 为鼠标提供的拖放API webworker (重点)Stor ...