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 ...
随机推荐
- UESTC_酱神赏花 2015 UESTC Training for Dynamic Programming<Problem C>
C - 酱神赏花 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 262143/262143KB (Java/Others) Submi ...
- Implement Hash Map Using Primitive Types
A small coding test that I encountered today. Question Using only primitive types, implement a fixed ...
- Alexandra and Prime Numbers(思维)
Alexandra and Prime Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- telnet如何操作Memcached缓存系统?
4.(1)telnet操作Memcached 许多语言都实现了连接memcached的客户端,其中以Perl.PHP为主.仅仅memcached网站上列出的语言就有:• Perl • PHP • Py ...
- 最逼近Mac OS的Linux系统 -- Elementary OS
也不知道有多少人听说过Elementary OS?elementary Project 最开始只有一个 elementary 主题,之后延伸出了很多项目,形成了 elementary Project ...
- linux C读取数据库
上次我们已经共同学习了在Linux下C连接数据库,下面一起学习用C语言来操作数据库. 1,首先要打开mysql的服务 [root@bogon ~]# service mysqld statusmysq ...
- linux中curl命令
linux curl是一个利用URL规则在命令行下工作的文件传输工具.它支持文件的上传和下载,所以是综合传输工具,但按传统,习惯称url为下载工具. 一,curl命令参数,有好多我没有用过,也不知道翻 ...
- 【Java基础】foreach循环
从一个小程序说起: class lesson6foreach { public static void main(String[] args) { int array[]={2,3,1,5,4,6}; ...
- android中跨进程通讯的4种方式
转自:http://blog.csdn.net/lyf_007217/article/details/8542359 帖子写的很好.看来一遍,试了一遍,感觉太有意义.必须转过来! android中跨进 ...
- 使用react-native做一个简单的应用-02项目搭建与运行
下面我们开始着手去做这一个项目,因为初学不久就开始边学边做,所以有些地方设计不太合理.请大家多多包涵.0.0 下面来介绍截图中的三个文件夹, GuoKuApp:是我开发app的文件夹. GuoKuDB ...