思路:

dp,使用了bitset优化。

实现:

 #include <bits/stdc++.h>
using namespace std;
const int N = ;
const int INF = 0x3f3f3f3f;
int a[N][N], b[N][N];
bitset<N * N * > dp[N][N]; int main()
{
int h, w;
while (cin >> h >> w)
{
for (int i = ; i < h; i++)
{
for (int j = ; j < w; j++)
{
cin >> a[i][j];
}
}
for (int i = ; i < h; i++)
{
for (int j = ; j < w; j++)
{
cin >> b[i][j];
}
}
for (int i = ; i < h; i++)
{
for (int j = ; j < w; j++)
{
dp[i][j].reset();
}
}
dp[][][a[][] - b[][] + N * N * ] = ;
dp[][][b[][] - a[][] + N * N * ] = ;
for (int i = ; i < h; i++)
{
for (int j = ; j < w; j++)
{
int tmp = abs(a[i][j] - b[i][j]);
if (j)
{
dp[i][j] |= dp[i][j - ] << tmp;
dp[i][j] |= dp[i][j - ] >> tmp;
}
if (i)
{
dp[i][j] |= dp[i - ][j] << tmp;
dp[i][j] |= dp[i - ][j] >> tmp;
}
}
}
int res = INF;
for (int i = ; i < N * N * ; i++)
{
if (dp[h - ][w - ][i]) res = min(res, abs(i - N * N * ));
}
cout << res << endl;
}
return ;
}

AtCoder Beginner Contest 147 E. Balanced Path的更多相关文章

  1. AtCoder Beginner Contest 147

    A - Blackjack #include <bits/stdc++.h> int main() { int a, b, c; scanf("%d%d%d", &am ...

  2. AtCoder Beginner Contest 177 题解

    AtCoder Beginner Contest 177 题解 目录 AtCoder Beginner Contest 177 题解 A - Don't be late B - Substring C ...

  3. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  4. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  5. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  6. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  7. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  8. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  9. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

随机推荐

  1. Django系列目录

    一:搭建自己的博客系列  搭建自己的博客(一):前期准备  搭建自己的博客(二):创建表,创建超级用户  搭建自己的博客(三):简单搭建首页和详情页 搭建自己的博客(四):优化首页和详情页 搭建自己的 ...

  2. Out of memory: Kill process 6033 (mysqld) score 85 or sacrifice child

    进入正题前先说明:OOM killer什么时候出现? linux下允许程序申请比系统可用内存更多的内存,这个特性叫Overcommit.这样做是出于优化系统考虑,因为不是所有的程序申请了内存就立刻使用 ...

  3. select和C标签

    <select name="cpcyModel.rwzj" id="cpcyModel_rwzj"> <option value=" ...

  4. Linux下DM无法显示建模界面的解决方法

    方法来源: http://www.linuxhospital.com/read/unable-to-resolve-function-glxqueryextension-in-hyperview.ht ...

  5. 【论文阅读】DCAN: Deep Contour-Aware Networks for Accurate Gland Segmentation

    DCAN: Deep Contour-Aware Networks for Accurate Gland Segmentation 作者:Hao Chen Xiaojuan Qi Lequan Yu ...

  6. windows 共享文件夹,和共享打印机

    达成的情形,目标主机上登陆用户设置密码,其他pc上需要目标主机的用户和密码才能访问其共享文件夹 步骤:1.目标主机,设置文件夹共享    在文件夹上右键-属性,点击共享选项卡,然后点击共享按钮,继续点 ...

  7. cmd命令net和sc

    来看windows中启动和关闭服务的方法:在cmd下可有两种方法打开,分别是net和sc. 1.net用于打开没有被禁用的服务, NET命令是功能强大的以命令行方式执行的工具. 它包含了管理网络环境. ...

  8. SQL Server DATEADD() 当前时间减7小时

  9. Socket: Java Socket 几个重要的TCP/IP选项解析(转)

    Socket选择可以指定Socket类发送和接受数据的方式.在JDK1.4中共有8个Socket选择可以设置.这8个选项都定义在java.net.SocketOptions接口中.定义如下: publ ...

  10. PHP如何防止注入及开发安全

    1.PHP注入的基本原理 程序员的水平及经验也参差不齐,相当大一部分程序员在编写代码的时候,没有对 用户输入数据的合法性进行判断,使应用程序存在安全隐患.用户可以提交一段数据 库查询代码,根据程序返回 ...