1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛
1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛
题目描述 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[][],x,y,f[][];
int main(){
cin>>R>>C;
cin>>k;
for(int i=;i<=k;i++){
cin>>x>>y;
map[x][y]=;
}
f[][]=;
for(int i=;i<=R;i++)
for(int j=;j<=C;j++){
if(i==) f[i][j]=max(f[i][j-],f[i][j]);
if(j==) f[i][j]=max(f[i-][j],f[i][j]);
if(i>&&j>) f[i][j]+=f[i-][j]+f[i][j-];
if(map[i][j]==) f[i][j]=;
}
cout<<f[R][C];
return ;
}
棋盘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了。
1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛的更多相关文章
- codevs 1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description You are a mouse that lives in a cage in ...
- code vs1262 不要把球传我(组合数学) 2012年CCC加拿大高中生信息学奥赛
1262 不要把球传我 2012年CCC加拿大高中生信息学奥赛 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题解 查看运行结果 题目描述 De ...
- 1269 匈牙利游戏 2012年CCC加拿大高中生信息学奥赛
1269 匈牙利游戏 2012年CCC加拿大高中生信息学奥赛 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description ...
- codevs 1262 不要把球传我 2012年CCC加拿大高中生信息学奥赛
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题目描述 Description CCC的足球比赛和传统的足球比赛有一点不同, 一次进球当且仅当先后接触到球的 ...
- 【动态规划】【记忆化搜索】【搜索】CODEVS 1262 不要把球传我 2012年CCC加拿大高中生信息学奥赛
可以暴力递归求解,应该不会TLE,但是我们考虑记忆化优化. 设f(i,j)表示第i个数为j时的方案数. f(i,j)=f(1,j-1)+f(2,j-1)+……+f(i-1,j-1) (4>=j& ...
- codevs 1277 生活大爆炸 2012年CCC加拿大高中生信息学奥赛
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题目描述 Description Sheldon and Leonard are physicists wh ...
- CODEVS——T 1269 匈牙利游戏 2012年CCC加拿大高中生信息学奥赛
http://codevs.cn/problem/1269/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Descript ...
- codevs——1267 老鼠的旅行(棋盘DP)
1267 老鼠的旅行 2012年CCC加拿大高中生信息学奥赛 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description ...
- codevs——T1267 老鼠的旅行
http://codevs.cn/problem/1267/ 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Descr ...
随机推荐
- Spark性能优化指南-高级篇(spark shuffle)
Spark性能优化指南-高级篇(spark shuffle) 非常好的讲解
- Knockout应用开发指南(完整版) 目录索引(转)
使用Knockout有一段时间了(确切的说从MIX11大会宣传该JavaScript类库以来,我们就在使用,目前已经在正式的asp.net MVC项目中使用),Knockout使用js代码达到双向绑定 ...
- [ HDOJ 3826 ] Squarefree number
\(\\\) \(Description\) \(T\)组数据,每次给出一个正整数 \(N\) ,判断其是否能被任意一个完全平方数整除. \(T\le 20,N\le 10^{18}\) \(\\\) ...
- Django基础之创建程序
环境配置 安装python35 安装django:pip install django==1.9.5 创建django程序 1.命令行创建django程序 A django-admin startpr ...
- 拒绝了对对象 'data'(数据库 'xxx',所有者 'dbo')的 SELECT 权限
拒绝了对对象 'data'(数据库 'xxx',所有者 'dbo')的 SELECT 权限解决的方法:1>在数据库里相应的用户权限中,把db_denydatareader的复选框的勾去掉.很多初 ...
- nginx--提供一键安装脚本
nginx特点 基于进程池实现的fastcgi 单一进程即可实现处理上千的连接 易于扩展的插件系统 安装篇 *下载源码 curl -O http://nginx.org/download/nginx- ...
- MFC_2.7 树控件的基本使用
树控件的基本使用 1.添加控件设置变量绑定 2.添加数据 HTREEITEM RootNode1 = m_TreeCtrl.InsertItem(L"北京"); HTREEITEM ...
- Android开发使用控件入门--环境搭建
Android开发使用控件入门--环境搭建 软件名称(,梦,,想.CAD ,控件) 1. 环境搭建: 3 1.1. 安装Eclipse 3 1.2. 下载JDK 3 1.3. 下载Android S ...
- JavaScipt30(第五个案例)(主要知识点:flex布局)
承接上文,这是第5个案例:这节没什么讲的,随便记录下吧,主要是用了flex布局与transform translateY,js部分和案例1类似. 附上项目链接: https://github.com/ ...
- ThinkPHP---案例1登录登出和添加部门
配置文件分3类:系统配置文件,分组配置文件,应用配置文件 ①系统配置文件ThinkPHP/Conf/convention.php: ②分组 / 模块 /平台配置文件Home/Conf/config.p ...