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 ...
随机推荐
- noip2014总结
noip总结 经过七周的停课,我们终于迎来了期盼已久的noip考试.在这一次的noip考试中,我们经历了很多,也收获了很多.当然这一次考试中也有很多值得总结的地方,特写此总结. 这一次考试考得还不错, ...
- Raphaël—JavaScript Library
Raphaël-JavaScript Library What is it? Raphaël is a small JavaScript library that should simplify yo ...
- 【转】DynDNS使用随笔
暂且小结一下: 1.下载编译客户端代码并交叉编译 首先,按照网上提示的步骤,在www.dyndns.com注册了帐号,并申请了域名,绑定了IP; 然后,在站点中找到客户端源码,其中ddclient是p ...
- $.cookie is not a function
在调试网站的时候,用jquery获取cookie时,报错: $.cookie is not a function; 一般情况$.cookie is not a function;错误原因: 一.没有引 ...
- textField 判断输入长度限制
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementS ...
- 关于Node.js, Jade一点小小的介绍。
本文出自:http://blog.csdn.net/svitter node.js大家知道的可能比較多,可是jade大家可能就不知道了.. GFW封杀掉google以后.今天在百度上找了好久也没有找到 ...
- 阿里云RDS导入服务器数据库 XtraBackup
如果是centos系统,默认会开启selinux 一定需关闭selinux 解决方法:关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=dis ...
- Cloudera Manager Free Edition 4.1 和CDH 4.1.2 简易安装教学
转载:http://fenriswolf.me/2012/12/06/cloudera-manager-free-edition-4-1-和-cdh-4-1-2-简易安装教学/ 安装及管理一个大的Ha ...
- Android中webView的基础使用(一)
WebView是View的一个子类,可以让你在activity中显示网页. 可以在布局文件中写入WebView:比如下面这个写了一个填满整个屏幕的WebView: <?xml version=& ...
- c语言字符串比较函数strcmp
strcmp(s1,s2) 说明: 当s1<s2时,返回值<0 当s1=s2时,返回值=0 当s1>s2时,返回值>0两个字符串自左向右逐个字符相比(按ASCII值大小相比较) ...