简单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. 引入的ajax中异步添加联系人

    申请出差控制器 中 填写联系人 直接在控制器中实例化联系人表,收集ajax提交的数据.插入表 public function addcontacts(){ $model = M('contacts') ...

  2. Bother

    Bother Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submis ...

  3. apache:添加cgi模式

    最终期望:通过配置apache的cgi能够使得apache能通过cgi方式连接go程序(因为我们的后端程序是用go语言写的). 实验1: 期望:通过配置cgi使得应用程序能够跑起来. go代码: pa ...

  4. gridview列绑定HyperLink

    <asp:HyperLink ID="HyperLink1" Target="_blank" runat="server" Navig ...

  5. token 入门教程

    下载 先去Apache下载一个tomcat 启动 进到安装目录的bin目录运行startup.bat,D:\apache-tomcat-8.0.33\bin (如果双击startup.bat一会自动关 ...

  6. 在 .NET 4 中使用托管可扩展性框架构建可组合的应用程序

    https://msdn.microsoft.com/zh-cn/library/ff576068.aspx http://blogs.msdn.com/b/nblumhardt/archive/20 ...

  7. JSP内置对象--4种属性范围 (pageContext,request,session,application)

    pageContext: javax.servlet.jsp.JspContext抽象类的父类JspContext 中有以下方法. request:javax.servlet.http.的接口Http ...

  8. 得到root,并且获取密码

    第一次使用ubuntu的时候 先使用这个命令 sudo passwd root 然后就可以改密码了

  9. 大varchar,test,blob数据类型的优化

    set global innodb-file-format=Barracuda 其它优化,后续补充

  10. parseint和parsefloat总结number。隐形转换

    parseint:会认识一些字符+.-.空格,其他的就会截止譬如23hudhchauch结果为:23,对于boollen类型不能转换为1或是0. number:是对整体的转换.对true的转换为1. ...