hdu 5569 matrix(简单dp)
Given a matrix with n rows and m columns ( n+m is an odd number ), at first , you begin with the number at top-left corner (,) and you want to go to the number at bottom-right corner (n,m). And you must go right or go down every steps. Let the numbers you go through become an array a1,a2,...,a2k. The cost isa1∗a2+a3∗a4+...+a2k−∗a2k. What is the minimum of the cost?
Several test cases(about ) For each cases, first come integers, n,m(≤n≤,≤m≤) N+m is an odd number. Then follows n lines with m numbers ai,j(≤ai≤)
For each cases, please output an integer in a line as the answer.
令dp[i][j]表示当前走到第i,j个位置的最小贡献,初始化做好了,然后根据i+j是奇数偶数的情况分别计算dp即可,最后要用long long。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 1006
#define inf 1<<29
ll n,m;
ll mp[N][N];
ll dp[N][N];
int main()
{
while(scanf("%I64d%I64d",&n,&m)==){
memset(dp,,sizeof(dp));
for(ll i=;i<=n;i++){
for(ll j=;j<=m;j++){
scanf("%I64d",&mp[i][j]);
}
}
for(ll i=;i<=n+;i++){
dp[i][]=inf;
mp[i][]=inf;
}
for(ll i=;i<=m+;i++){
dp[][i]=inf;
mp[][i]=inf;
} dp[][]=mp[][];
dp[][]=mp[][]*mp[][];
dp[][]=mp[][]*mp[][];
for(ll i=;i<=n;i++){
for(ll j=;j<=m;j++){
if(i== && j==) continue;
if(i== && j==) continue;
if(i== && j==) continue;
if((i+j)%==){
dp[i][j]=min(dp[i-][j],dp[i][j-]);
//printf("i , j %d %d %d\n",i,j,dp[i][j]);
}
else{
dp[i][j]=min(dp[i-][j]+mp[i-][j]*mp[i][j],dp[i][j-]+mp[i][j-]*mp[i][j]);
//printf("i , j %d %d %d\n",i,j,dp[i][j]);
} }
} printf("%I64d\n",dp[n][m]);
}
return ;
}
hdu 5569 matrix(简单dp)的更多相关文章
- HDU 5569 matrix
简单DP /* *********************************************** Author :Zhou Zhentao Email :774388357@qq.com ...
- hdu 5569 matrix dp
matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5569 D ...
- HDU 2686 Matrix 多线程dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2686 思路:多线程dp,参考51Nod 1084:http://www.51nod.com/onlin ...
- hdu 4576 (简单dp+滚动数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 题意:给出1~n的环,m个操作,每次能顺时针或逆时针走w步,询问最后在l~r这段区间内概率.(1 ...
- HDU 2836 Traversal 简单DP + 树状数组
题意:给你一个序列,问相邻两数高度差绝对值小于等于H的子序列有多少个. dp[i]表示以i为结尾的子序列有多少,易知状态转移方程为:dp[i] = sum( dp[j] ) + 1;( abs( he ...
- HDU 4313 Matrix 树形dp
题意: 给定n个点的树,m个黑点 以下n-1行给出边和删除这条边的费用 以下m个黑点的点标[0,n-1] 删除一些边使得随意2个黑点都不连通. 问删除的最小花费. 思路: 树形dp 每一个点有2个状态 ...
- hdu 2128 Frog(简单DP)
Frog Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
- (动态规划)matrix -- hdu -- 5569
http://acm.hdu.edu.cn/showproblem.php?pid=5569 matrix Time Limit: 6000/3000 MS (Java/Others) Memo ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
随机推荐
- C# Switch is Type
常规用法: Type t = sender.GetType(); if (t == typeof(Button)) { var realObj = (Button)sender; // Do Some ...
- The type R is already defined 错误解决办法
今天在导入一个开源项目的时候遇到了The type R is already defined的错误,试过了删除R,clear project都还是报这个错,Google一下之后找到了解决办法在 Pro ...
- poj 3352 双连通分量
至少加几条边成为双连通分量 #include <iostream> #include <cstdio> #include <cstring> using names ...
- H5单页面架构:requirejs + angular + angular-route
说到项目架构,往往要考虑很多方面: 方便.例如使用jquery,必然比没有使用jquery方便很多,所以大部分网站都接入类似的库: 性能优化.包括加载速度.渲染效率: 代码管理.大型项目需要考虑代码的 ...
- C#中操作刚导出的Excel,设置其为自动调整列宽
[问题] 用C#导出数据为excel,但是导出的数据中,不是自动调整列宽的: 希望变成这样的: [解决过程] 1.参考: 在C#里对excel文件的列宽进行操作 去试试: //auto adjust ...
- SQL事务机制
一.事务概念 事务是一种机制.是一种操作序列,它包含了一组数据库操作命令,这组命令要么全部执行,要么全部不执行.因此事务是一个不可分割的工作逻辑单元.在数据库系统上执行并发操作时事务是作为最小 ...
- vs2010 中检测到有潜在危险的 Request.Form 值
解决方法 : 一般在网上搜只有以下两种处理方式: 1.在报错的页面前吧<%Page%>标签中增加validateRequest="false"的属性为false 如下所 ...
- Perfect Squares
Perfect Squares Total Accepted: 18854 Total Submissions: 63048 Difficulty: Medium Given a positive i ...
- Submission Details
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- Js中JSON.stringify()与JSON.parse()与eval()详解及使用案例
JSON(JavaScript Object Notation)是一种轻量级的数据交换格式.因为采用独立于语言的文本格式,也使用了类似于C语言家族的习惯,拥有了这些特性使使JSON称为理想的数据交换语 ...