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. apache配置-html碎片shtml格式

    修改SSI 文件 conf–httpd.conf <Directory "D:/Android/Apache2.2/htdocs">  //修改文件目录 # # Pos ...

  2. pycharm最新code码,分享给大家

    最新的pycharm激活码,到明年11月份,一名努力的Python程序员 这俩天,在忙学校布置的小项目,给大家更新少了,我会慢慢补上的,努力学pycharm,有什么问题可以问我哦,我竭尽所能帮大家解答 ...

  3. 30.Odoo产品分析 (四) – 工具板块(2) – 搜索和仪表盘(2)

    查看Odoo产品分析系列--目录 在前面的模块中,简单介绍过了odoo如何搜索系统中的各种数据集,并保存这些过滤器,以便在之后需要时能够轻松访问这些过滤器.这里将做更详细的介绍.最后分析仪表盘的功能, ...

  4. C#:如何使方法过时,如何否决方法

    在使用.Net Frameworkd进行开发时,经常可以在方法的智能提示ToolTip上面看到一个方法是[否决的],如图: 或者在警告里面: 甚至使用[否决的]方法的时候还会造成编译错误: 上面的这些 ...

  5. codeforces 2A Winner (好好学习英语)

    Winner 题目链接:http://codeforces.com/contest/2/problem/A ——每天在线,欢迎留言谈论. 题目大意: 最后结果的最高分 maxscore.在最后分数都为 ...

  6. mysql之用户权限管理

    本文内容: 什么是用户权限 恰当的用户权限 查看权限 修改权限 删除权限 首发日期:2018-04-19 什么是用户权限: 每个用户都有自己的用户权限,这些用户权限比如有查询表权限.修改表权限.插入表 ...

  7. ORACLE中Scalar subquery Caching的hash table大小测试浅析

      前阵子总结了这篇"ORACLE当中自定义函数性优化浅析"博客,里面介绍了标量子查询缓存(scalar subquery caching),如果使用标量子查询缓存,ORACLE会 ...

  8. java防止double和float精度丢失的方法

    在浮点数当中做运算时经常会出现精度丢失的情况,如果做项目不作处理的话会对商家造成很大的影响的.项目尤其是金融相关的项目对这些运算的精度要求较高. 问题原因:首先计算机进行的是二进制运算,我们输入的十进 ...

  9. mysql中导入导出sql文件

    1.导出整个数据库: mysqldump -u用户名 -p密码 数据库名 > 导出的文件名 例:mysqldump -uroot -proot user > user.sql 2.导出一个 ...

  10. HttpHandler实现网页图片防盗链

    using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary ...