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

题目描述 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

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long int R,C,k,map[100][100],x,y,f[100][100];
int main(){cin>>R>>C;cin>>k;for(int i=1;i<=k;i++){cin>>x>>y;map[x][y]=1;}f[1][1]=1;for(int i=1;i<=R;i++)    for(int j=1;j<=C;j++){if(i==1)    f[i][j]=max(f[i][j-1],f[i][j]);if(j==1)    f[i][j]=max(f[i-1][j],f[i][j]);if(i>1&&j>1)    f[i][j]+=f[i-1][j]+f[i][j-1];if(map[i][j]==1)    f[i][j]=0;}cout<<f[R][C];return 0;
}

棋盘DP

 

1

2

3

4

5

6

7

8

1

0

1

0

1

0

0

1

0

2

1

0

0

1

1

0

1

0

3

0

0

0

0

0

0

0

0

4

0

1

0

0

1

0

0

1

5

0

1

0

0

0

0

1

0

6

0

0

1

1

1

1

0

0

7

1

0

0

0

0

0

1

1

8

0

0

0

0

0

1

0

0

如图所示:

这是一个比上一个题简单的DP很容易列出状态转移方程

当没有猫时 f[i][j]=+f[i][j-1]+f[i-1][j];

当有猫时   f[i][j]=0;

在考虑一下特殊的情况就OK了。

转载于:https://www.cnblogs.com/cangT-Tlan/p/6747153.html

1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛相关推荐

  1. CODE[VS] 1275有鱼的声音 2012年CCC加拿大高中生信息学奥赛

    题目描述 Description A fish-finder is a device used by anglers to find fish in a lake. If the fish-finder finds ...

  2. 【2012年中山纪念中学信息学竞赛初一选拔赛一】美丽的纪中(a)

    [2012年中山纪念中学信息学竞赛初一选拔赛一]美丽的纪中(a) (File IO): input:a.in output:a.out 时间限制: 1000 ms 空间限制: 262144 KB [题 ...

  3. 【2012年中山纪念中学信息学竞赛初一选拔赛一】纪中篮球联赛(b)

    [2012年中山纪念中学信息学竞赛初一选拔赛一]纪中篮球联赛(b) (File IO): input:b.in output:b.out 时间限制: 1000 ms 空间限制: 262144 KB [ ...

  4. 【2012年中山纪念中学信息学竞赛初一选拔赛一】纪中作业(c)

    [2012年中山纪念中学信息学竞赛初一选拔赛一]纪中作业(c) (File IO): input:c.in output:c.out 时间限制: 1000 ms 空间限制: 262144 KB [题目 ...

  5. 合肥市noi计算机竞赛,2012年蜀山区青少年信息学(计算机)竞赛通知

    合肥奥数网讯:关于举办2012年蜀山区青少年信息学(计算机)竞赛的通知如下 蜀山区各小学: 为进一步推动中小学计算机教育的开展,促进我区学生信息学(计算机)知识的普及与提高,同时为合肥市青少年信息学( ...

  6. 【2012年中山纪念中学信息学竞赛初一选拔赛一】纪中游戏(d)

    [2012年中山纪念中学信息学竞赛初一选拔赛一]纪中游戏(d) (File IO): input:d.in output:d.out 时间限制: 1000 ms 空间限制: 262144 KB [题目 ...

  7. ccc加拿大计算机竞赛在线评测系统,加拿大计算机竞赛简介

    原标题:加拿大计算机竞赛简介 加拿大计算机竞赛 加拿大计算机竞赛(Canadian Computing Competition,简称CCC)是加拿大面向中学生每年举办一次的计算机程序设计比赛,比赛的目 ...

  8. 信息学奥赛C++语言:旅行

    [题目描述] 帅帅和随同爸爸一起开车去旅行.但是车上的里程表坏了,所以他们不知道他们行驶了多少英里?幸运的是,帅帅有一只完好的秒表,所以他们可以把汽车的速度和行驶总时间记录下来.然而,他们的记录方法有 ...

  9. 信息学奥赛一本通 1343:【例4-2】牛的旅行 | 洛谷 P1522 [USACO2.4] 牛的旅行 Cow Tours

    [题目链接] ybt 1343:[例4-2]牛的旅行 洛谷 P1522 [USACO2.4] 牛的旅行 Cow Tours [题目考点] 1. 图论 最短路径 Floyd算法 Floyd算法时间复杂度 ...

最新文章

  1. SharePoint 客户端经常弹出Windows验证登录框问题
  2. Netbeans and Remote Host for C/C++ Developing
  3. SQL 语句中对于like 的调优
  4. 【机器学习】数据不平衡问题都怎么解?
  5. [导入]用Javascript实现interface的类似功能
  6. 大剑无锋之Spark中的Driver是什么?【面试推荐】
  7. android主动显示流程,Activity加载显示基本流程
  8. 第一行Java代码,java高级面试笔试题
  9. 面试必会之ArrayList源码分析手写ArrayList
  10. Linux 命令(136)—— curl 命令
  11. 【图像去噪】基于matlab GUI HSI彩色图像去噪【含Matlab源码 1786期】
  12. “中华优秀科普图书榜”
  13. windows安装telnet工具
  14. Android中铃声总结源码
  15. 计算机病毒无法破坏压缩文件,求解压缩文件拒绝访问是怎么回事?
  16. 2021湖北技能高考文化综合成绩查询,2021年湖北省技能高考文化综合考试大纲.pdf...
  17. 量子计算机研制成功图片,光量子计算机的曙光:科学家成功研制出量子光源
  18. 《Windows CE嵌入式开发入门——基于Xscale架构》第4章 外设控制器
  19. HENUOJ-1007-CYT大佬的女装(贪心算法)
  20. WINDOWS的常用软件点评(1)------系统必备软件篇

热门文章

  1. 这款小程序 能让你和孙悟空一样 可以七十二变
  2. 易燃易爆炸。你根本不爱我。
  3. 设计自己的地图叠加到 Google Maps或者 MicroSoft Vitual Earth
  4. 歌曲用计算机弹出来网红英语歌,最近抖音很火的英文歌
  5. 20150109-放弃了一切希望
  6. 叶问短线绝招之拨云见日
  7. Top01-0010、img标签的属性
  8. 2012-10-19《商业英语中的加班表达…
  9. MAC上Cisco AnyConnect删除不干净,造成无法重新安装的解决办法
  10. 建议118:使用SecureString保存密钥等机密字符串