Lougu2295 MICE

给一个 \(n\times m\) 的矩阵 \(a\) ,求一条从 \((1,\ 1)\) 到 \((n,\ m)\) 的最短路径,使得与路径相接的所有网格的权值和最小

\(n,\ m\leq10^3,\ 0\leq a_{i,j}\leq100\)

dp


令 \(f_{0/1,\ i,\ j}\) 表示,走到 \((i,\ j)\) 时,上一步是向下走/向右走的最优值

代码

#include <bits/stdc++.h>
using namespace std; #define nc getchar()
const int maxn = 1010;
int n, m, a[maxn][maxn], f[2][maxn][maxn]; inline int read() {
int x = 0; char c = nc;
while (c < 48) c = nc;
while (c > 47) x = x * 10 + c - 48, c = nc;
return x;
} int main() {
n = read(), m = read();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
a[i][j] = read();
}
}
memset(f, 0x3f, sizeof f);
f[0][1][1] = f[1][1][1] = a[1][1] + a[1][2] + a[2][1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (i == 1 && j == 1) continue;
f[0][i][j] = min(f[0][i - 1][j] + a[i][j - 1], f[1][i - 1][j]) + a[i + 1][j] + a[i][j + 1];
f[1][i][j] = min(f[0][i][j - 1], f[1][i][j - 1] + a[i - 1][j]) + a[i + 1][j] + a[i][j + 1];
}
}
printf("%d", min(f[0][n][m], f[1][n][m]));
return 0;
}

Luogu2295 MICE的更多相关文章

  1. Bag of mice(CodeForces 148D )

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  2. 1056. Mice and Rice (25)

    时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and Rice is the name of a pr ...

  3. CF 148D. Bag of mice (可能性DP)

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. code forces 148D Bag of mice (概率DP)

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  5. R语言︱缺失值处理之多重插补——mice包

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 笔者寄语:缺失值是数据清洗过程中非常重要的问题 ...

  6. PAT1056:Mice and Rice

    1056. Mice and Rice (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice an ...

  7. CF797F Mice and Holes 贪心、栈维护DP

    传送门 首先\(\sum c\)有些大,考虑将其缩小降低难度 考虑一个贪心:第一次所有老鼠都进入其左边第一个容量未满的洞(如果左边没有就进入右边第一个未满的洞),第二次所有老鼠都进入其右边第一个容量未 ...

  8. A1056. Mice and Rice

    Mice and Rice is the name of a programming contest in which each programmer must write a piece of co ...

  9. PAT甲题题解-1056. Mice and Rice (25)-模拟题

    有n个老鼠,第一行给出n个老鼠的重量,第二行给出他们的顺序.1.每一轮分成若干组,每组m个老鼠,不能整除的多余的作为最后一组.2.每组重量最大的进入下一轮.让你给出每只老鼠最后的排名.很简单,用两个数 ...

随机推荐

  1. BZOJ2655: calc(dp 拉格朗日插值)

    题意 题目链接 Sol 首先不难想到一个dp 设\(f[i][j]\)表示选了\(i\)个严格递增的数最大的数为\(j\)的方案数 转移的时候判断一下最后一个位置是否是\(j\) \[f[i][j] ...

  2. 2018-04-27 搭建Python官方文档翻译环境-汉化示例代码

    通过官方i18n流程, 实现文档中的代码段的汉化, 效果如下(4. More Control Flow Tools): 步骤 基于python官方3.6版文档cpython/Doc生成pot文件. 参 ...

  3. 初识HTTP协议web开发

    HTTP协议  HTTP协议简介 超文本传输协议(英文:HyperText Transfer Protocol,缩写:HTTP)是一种用于分布式.协作式和超媒体信息系统的应用层协议.HTTP是万维网的 ...

  4. 照葫芦画瓢系列之Java --- eclipse下使用maven创建Struts 2项目

    一.创建Maven项目 http://www.cnblogs.com/zhanqun/p/8425571.html 二.添加struts2核心依赖包以及其他依赖项 打开pom.xm配置界面 点击Add ...

  5. Linux内核线程的思考与总结

    1.内核线程,只是一个称呼,实际上就是一个进程,有自己独立的TCB,参与内核调度,也参与内核抢占. 这个进程的特别之处有两点,第一.该进程没有前台.第二.永远在内核态中运行. 2.创建内核线程有两种方 ...

  6. 深入理解Java虚拟机01--概述

    本课题是对<深入理解Java虚拟机>周志明 第二版的总结   具体可以参考:https://pan.baidu.com/s/1v_mPp--XV4u4rCBMkbR37A 第1版 可以忽略 ...

  7. 章节四、4-For循环

    一.For循环格式 package introduction5; public class ForLoopDemo { public static void main(String[] args) { ...

  8. linux文件统计命令和目录统计命令

    1.统计本目录下除`./apps/myapp/migrations`的所有py文件 wc -l `find -path . -o -name '*py' ! -path "./apps/my ...

  9. django CharField按整形排序

    #models.py from django.db import models class Block(models.Model): ... height = models.CharField(max ...

  10. 决策树ID3算法的java实现(基本适用所有的ID3)

    已知:流感训练数据集,预定义两个类别: 求:用ID3算法建立流感的属性描述决策树 流感训练数据集 No. 头痛 肌肉痛 体温 患流感 1 是(1) 是(1) 正常(0) 否(0) 2 是(1) 是(1 ...