https://www.codechef.com/problems/LEMOUSE


题意:

有一个n *m的网格。有一头大象,初始时在(1,1),要移动到(n,m),每
次只能向右或者向下走。有些格子中有老鼠,如果大象所在的格子和某个有老
鼠的格子的曼哈顿距离$\e$1,大象就会被那只老鼠吓到。
求一条移动路径,使得吓到过大象的老鼠数量最少。n;m $\le$100。


开始刷济南集训hzc的课件啦!

最简单的一道$DP$

一只老鼠只会吓大象一次$f[i][j][0/1]$记录从左还是上走来的,转移时讨论一下就行了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N=,INF=1e9+;
double eps=1e-;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int m,n,a[N][N],s[N][N];
char str[N];
int f[N][N][];
void dp(){
f[][][]=f[][][]=s[][];
for(int i=;i<=m;i++)
for(int j=;j<=n;j++){
if(i==&&j==) continue;
if(j-!=){
int t1=INF,t2=INF;
if(j-!=||i==)
t1=f[i][j-][];
if(i-!=)
t2=f[i][j-][]-a[i-][j];
f[i][j][]=min(t1,t2)+s[i][j]-a[i][j-]-a[i][j];
}
if(i-!=){
int t1=INF,t2=INF;
if(i-!=||j==)
t1=f[i-][j][];
if(j-!=)
t2=f[i-][j][]-a[i][j-];
f[i][j][]=min(t1,t2)+s[i][j]-a[i-][j]-a[i][j];
}
}
//for(int i=1;i<=m;i++) for(int j=1;j<=n;j++) printf("f %d %d %d %d\n",i,j,f[i][j][0],f[i][j][1]);
//for(int i=1;i<=m;i++) for(int j=1;j<=n;j++) printf("%d%c",f[i][j][0],j==n?'\n':' ');puts("");
//for(int i=1;i<=m;i++) for(int j=1;j<=n;j++) printf("%d%c",f[i][j][1],j==n?'\n':' ');puts(""); printf("%d\n",min(f[m][n][],f[m][n][]));
}
int main(){
freopen("in","r",stdin);
int T=read();
while(T--){
m=read();n=read();
memset(s,,sizeof(s));
for(int i=;i<=m;i++){
scanf("%s",str+);
for(int j=;j<=n;j++){
a[i][j]=str[j]-'';
if(a[i][j]) s[i][j]++,s[i-][j]++,s[i+][j]++,s[i][j-]++,s[i][j+]++;
}
}
//for(int i=1;i<=m;i++) for(int j=1;j<=n;j++) printf("%d%c",a[i][j],j==n?'\n':' ');puts("");
//for(int i=1;i<=m;i++) for(int j=1;j<=n;j++) printf("%d%c",s[i][j],j==n?'\n':' ');puts(""); dp();
}
}

CodeChef Little Elephant and Mouses [DP]的更多相关文章

  1. CodeChef Little Elephant and Movies [DP 排列]

    https://www.codechef.com/FEB14/problems/LEMOVIE 题意: 对于一个序列,定义其“激动值”为序列中严格大于前面所有数的元素的个数.给定n个数p1;,p2.. ...

  2. CodeChef Cards, bags and coins [DP 泛型背包]

    https://www.codechef.com/problems/ANUCBC n个数字,选出其一个子集.求有多少子集满足其中数字之和是m的倍数.n $\le$ 100000,m $\le$ 100 ...

  3. HDU 5434 Peace small elephant 状压dp+矩阵快速幂

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant  Accepts: 38  Submissions: ...

  4. CF 258B Little Elephant and Elections [dp+组合]

    给出1,2,3...m 任取7个互不同样的数a1,a2,a3,a4,a5,a6,a7 一个数的幸运度是数位上4或7的个数 比方244.470幸运度是2. 44434,7276727.4747,7474 ...

  5. codechef Little Elephant and Permutations题解

    The Little Elephant likes permutations. This time he has a permutation A[1], A[2], ..., A[N] of numb ...

  6. codechef Little Elephant and Bombs题解

    The Little Elephant from the Zoo of Lviv currently is on the military mission. There are N enemy bui ...

  7. CodeChef Little Elephant and Balance

    Given an array A1,A2...AN, you have to print the size of the largest contiguous subarray such that L ...

  8. CodeChef:Little Elephant and Colored Coins

    类似墨墨的等式 设f[2][j][k]表示a[i].c是否和当前颜色相同,到当前枚举到的颜色为止,颜色数为j,对mnv取模为k的最小数 这是个无限循环背包,用spfa优化 #include<cs ...

  9. CTSC 2018酱油记

    Day0 5.5 花了一上午的时间把codechef div2的前四题切了,又在zbq老司机的指导下把第五题切了 中午12:00 gryz电竞组从机房出发,临走的时候看到很多学长挺恋恋不舍的,毕竟可能 ...

随机推荐

  1. Open-air shopping malls(二分半径,两元交面积)

    http://acm.hdu.edu.cn/showproblem.php?pid=3264 Open-air shopping malls Time Limit: 2000/1000 MS (Jav ...

  2. Windows系统下文件的概念及c语言对其的基本操作(丙)

  3. sass 安装与使用

    1.安装. 安装ruby :http://rubyinstaller.org/downloads 创建项目:在f盘创建一个名为sass的文件夹 ruby命令行:f: ruby命令行:cd sass r ...

  4. angularJS 与angujs-sku实现购物车组合查询

    原网址:http://sentsin.com/web/1069.html   demo : https://codepen.io/hzxs1990225/pen/VYyOdW  修复版文件下载:htt ...

  5. [国嵌攻略][143][LCD驱动程序分析]

    LCD驱动程序分析 LCD驱动程序代码在/drivers/video/s3c2410fb.c文件中,在该驱动的s3c2410fb_init中注册了平台驱动,该驱动的初始化代码在s3c24xxfc_pr ...

  6. Java技术分享:如何编写servlet程序

    身为计算机专业的我,从接触java至今,已经有七年之久,从最开始的小白到现在的大白,这是一个漫长而曲折的历程. 大学刚接触Java这个学科时,一点儿都不理解java是要干嘛的,只知道学起来肯定不容易, ...

  7. 安装Ruby、Sass与Compass

    sass基于Ruby语言开发而成,因此安装sass前需要安装Ruby.(注:mac下自带Ruby无需在安装Ruby!) window下安装SASS首先需要安装Ruby,先从官网下载Ruby并安装.安装 ...

  8. phpstorm 怎么实现分屏展示

  9. css中,如何设置前景色的透明度?

    谢谢 我等待的他 | 浏览 255446 次 推荐于2016-01-13 12:27:03 最佳答案 css控制透明度倒不麻烦. filter:alpha(opacity=50); -moz-opac ...

  10. 邓_thinkphp口试

    描述php框架开发 通过提供一个开发Web程序的基本架构,PHP开发框架把PHPWeb程序开发摆到了流水线上.换句话说,PHP开发框架有助于促进快速软件开发(RAD),这节约了你的时间,有助于创建更为 ...