HDU 5569 matrix
简单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的更多相关文章
- hdu 5569 matrix dp
matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5569 D ...
- 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 ...
- (动态规划)matrix -- hdu -- 5569
http://acm.hdu.edu.cn/showproblem.php?pid=5569 matrix Time Limit: 6000/3000 MS (Java/Others) Memo ...
- HDU 4920 Matrix multiplication(bitset)
HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...
- HDU 2686 Matrix 3376 Matrix Again(费用流)
HDU 2686 Matrix 题目链接 3376 Matrix Again 题目链接 题意:这两题是一样的,仅仅是数据范围不一样,都是一个矩阵,从左上角走到右下角在从右下角走到左上角能得到最大价值 ...
- hdu 2686 Matrix 最小费用最大流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 Yifenfei very like play a number game in the n*n ...
- hdu 2119 Matrix(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2119 Matrix Time Limit: 5000/1000 MS (Java/Others) ...
- HDU 5671 Matrix 水题
Matrix 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5671 Description There is a matrix M that has ...
- HDU - 233 Matrix
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5015 解题思路:一看到题目,感觉是杨辉三角形,然后用组合数学做,不过没想出来怎么做,后来看数据+递推思 ...
随机推荐
- C#未将对象引用设置到对象的实例
未将对象引用设置到对象的实例,这个错误的意思是对象为null,但你还要去取里面的值,所以计算机就不干了.解决办法一般是:用一个你不能确定是不是为null的对象时,尽量做个判断.if(object!=n ...
- debia下安装libjpeg
今天在编译时遇到如下问题: configure: error: no usable libjpeg; please install libjpeg devel package or equivalen ...
- 构造DataTable
手动构造一个DataTable: DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(string)); dt. ...
- A Bit Fun
A Bit Fun Time Limit : 5000/2500ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Sub ...
- LINQ&EF in 用算的写法 like
- 转 oracle 如何停下oracle 服务
设置SET ORACLE_SID=ORCL ORCL--实例名称 --停止oracle实例服务 C:\Users\Administrator>net stop oracleserviceORCl ...
- GDB: basics
Before Debugging, generating the debugging info using gcc -g3 *.c/cpp; then gdb ~.out/exe using comm ...
- HDU2066一个人的旅行/最短路问题
一个人的旅行 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- maven项目转成web项目
1.右键项目,Install Dynamic Web Module Facet
- XListview的下拉刷新、上拉加载、用Pull解析XML
做之前需要导入XListview的文件,此是用第三方的xListview实现的,东西没写全.此是在Fragment中实现的 //--------------XListView的布局---------- ...