HDU_4826_dp
Labyrinth
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 974 Accepted Submission(s): 431
每组数据的第一行输入两个正整数m,n(m<=100,n<=100)。接下来的m行,每行n个整数,分别代表相应格子中能得到金币的数量,每个整数都大于等于-100且小于等于100。
每组测试数据输出一行,输出一个整数,代表根据最优的打法,你走到右上角时可以获得的最大金币数目。
2 -2
3
18
4
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define INF -10000000
int mapp[][];
int dp[][][]; int main()
{
int t,cnt=;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=; i<=n; i++)
for(int j=; j<=m; j++)
scanf("%d",&mapp[i][j]);
for(int i=;i<;i++)
for(int j=;j<;j++)
for(int k=;k<;k++)
dp[i][j][k]=INF;
dp[][][]=;
for(int i=;i<=n;i++)
dp[][i][]=dp[][i][]=dp[][i-][]+mapp[i][];
for(int j=;j<=m;j++)
for(int i=;i<=n;i++)
{
dp[][i][j]=dp[][i][j]=max(dp[][i][j-],dp[][i][j-])+mapp[i][j];
for(int k=i;k<=n;k++)
dp[][k][j]=max(dp[][k][j],dp[][k-][j]+mapp[k][j]);
for(int k=i;k>=;k--)
dp[][k][j]=max(dp[][k][j],dp[][k+][j]+mapp[k][j]);
}
printf("Case #%d:\n%d\n",++cnt,max(dp[][][m],dp[][][m]));
}
return ;
}
HDU_4826_dp的更多相关文章
随机推荐
- 将完整的Maven远程存储库下载到本地存储库(别试了,不太可取)
别试了,这种方式不太可取. 要解决可以有如下思路: 1.做成镜像站点,有如下命令: wget -m http://site.to.mirror.com #-m代表“镜子”. rsync repo1.m ...
- linux下让irb实现代码自己主动补全的功能
我不知道其它系统上irb是否有此功能,可是在ubuntu上ruby2.1.2自带的irb默认是没有代码自己主动补全功能的,这多少让人认为有所不便.事实上加上也非常easy,就是在irb里载入一个模块: ...
- [Vue @Component] Define Props on a Vue Class with vue-property-decorator
While traditional Vue components require a data function which returns an object and a method object ...
- C#趣味程序---九九乘法表
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { for ...
- 工作总结 c#如何将两个List集合合并
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- LeetCode 266. Palindrome Permutation (回文排列)$
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- Mysql经常使用函数
-----------------------------字符串函数--------------------------------------- ----拼接字符串.不论什么字符串与null拼接为n ...
- poj3254Corn Fields
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13765 Accepted: 7232 Desc ...
- 重启标志log
01) fatal error : 如下: [ >.()[:swapper/][name:disp_lcm&][DISP]disp_lcm_probe [ >.()[:swappe ...
- sql server的版本检查
https://support.microsoft.com/en-ph/help/321185/how-to-determine-the-version-edition-and-update-leve ...