简单DP

/* ***********************************************
Author :Zhou Zhentao
Email :774388357@qq.com
Created Time :2015/11/21 9:45:58
File Name :acm.cpp
************************************************ */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std; int mat[+][+];
int flag[+][+];
int dp[+][+];
int n,m; int main()
{
while(~scanf("%d%d",&n,&m)){ for(int i=;i<n;i++)
for(int j=;j<m;j++)
scanf("%d",&mat[i][j]); flag[][]=;
for(int i=;i<m;i++) flag[][i]=abs(-flag[][i-]); for(int i=;i<n;i++)
for(int j=;j<m;j++)
flag[i][j]=abs(-flag[i-][j]); for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(i==&&j==) dp[i][j]=;
if(i==)
{
if(flag[i][j]==)
{
dp[i][j]=dp[i][j-]+mat[i][j]*mat[i][j-];
}
else
{
dp[i][j]=dp[i][j-];
}
}
else if(j==)
{
if(flag[i][j]==)
{
dp[i][j]=dp[i-][j]+mat[i][j]*mat[i-][j];
}
else
{
dp[i][j]=dp[i-][j];
}
}
else
{
if(flag[i][j]==)
{
dp[i][j]=min(dp[i][j-]+mat[i][j]*mat[i][j-],dp[i-][j]+mat[i][j]*mat[i-][j]);
} else
{
dp[i][j]=min(dp[i][j-],dp[i-][j]);
}
}
}
}
printf("%d\n",dp[n-][m-]);
}
return ;
}

HDU 5569 matrix的更多相关文章

  1. hdu 5569 matrix dp

    matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5569 D ...

  2. hdu 5569 matrix(简单dp)

    Problem Description Given a matrix with n rows and m columns ( n+m ,) and you want to go to the numb ...

  3. (动态规划)matrix -- hdu -- 5569

    http://acm.hdu.edu.cn/showproblem.php?pid=5569 matrix Time Limit: 6000/3000 MS (Java/Others)    Memo ...

  4. HDU 4920 Matrix multiplication(bitset)

    HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...

  5. HDU 2686 Matrix 3376 Matrix Again(费用流)

    HDU 2686 Matrix 题目链接 3376 Matrix Again 题目链接 题意:这两题是一样的,仅仅是数据范围不一样,都是一个矩阵,从左上角走到右下角在从右下角走到左上角能得到最大价值 ...

  6. hdu 2686 Matrix 最小费用最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 Yifenfei very like play a number game in the n*n ...

  7. hdu 2119 Matrix(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2119 Matrix Time Limit: 5000/1000 MS (Java/Others)    ...

  8. HDU 5671 Matrix 水题

    Matrix 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5671 Description There is a matrix M that has ...

  9. HDU - 233 Matrix

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5015 解题思路:一看到题目,感觉是杨辉三角形,然后用组合数学做,不过没想出来怎么做,后来看数据+递推思 ...

随机推荐

  1. Chapter 2 Open Book——14

    I backpedaled. "They seemed nice enough to me. I just noticed they keptto themselves. 我改口说道,他们看 ...

  2. ASP.NET 修改密码代码

    using System; using System.Data; using System.Configuration; using System.Collections; using System. ...

  3. html元素中class属性值多个空格分格是什么意思?

    即指定多个class,这是bootstrap常干的事,比如 <div class="alert alert-info"> 请问,这两个class之间的关系是什么,二者的 ...

  4. SOM聚类与Voroni图在验证码字符分割中的应用

    http://www.docin.com/p-1300981517.html SOM聚类与Voroni图在验证码字符分割中的应用  

  5. HDU2673:shǎ崽 OrOrOrOrz

    Problem Description Acmer in HDU-ACM team are ambitious, especially shǎ崽, he can spend time in Inter ...

  6. Adobe Flash CC 2014 下载及破解

    来源 :http://prodesigntools.com/adobe-cc-2014-direct-download-links.html 地址:http://trials3.adobe.com/A ...

  7. chrome 常用快捷操作

    Chrome窗口和标签页快捷键: Ctrl+N 打开新窗口 Ctrl+T 打开新标签页 Ctrl+Shift+N 在隐身模式下打开新窗口 Ctrl+O,然后选择文件,在谷歌浏览器中打开计算机上的文件 ...

  8. JavaScript焦点事件、鼠标事件和滚轮事件使用详解

    网址:http://www.jb51.net/article/78094.htm

  9. SQL添加表字段以及SQL查询表,表的所有字段名

    通用式: alter table [表名] add [字段名] 字段属性 default 缺省值 default 是可选参数 增加字段: alter table [表名] add 字段名 smalli ...

  10. EL表达式处理字符串 是否 包含 某字符串 截取 拆分...............

    EL表达式处理字符串 是否 包含 某字符串 截取 拆分............... JSP页面页头添加<%@ taglib uri="/WEB-INF/taglib/c.tld&qu ...