【HDU】 2118 Mouse
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2118
首先吐槽题目,出题人的表述很容易让人不知所云啊!
在这里解释下题目意思:
A greedy mouse cici ate rat poison by mistake. To save herself, she have to drink.
一只贪心的老鼠CiCi 误吃了老鼠药。为了进行自救,她必须喝(显然应该是喝解药吧?)

Cici can only walk in four ways that marked in the photoes followed and only move in the region that colored blue..She expend energy every step.There are cheese in every position which cici can eat to gain energy once she is there.He will never reach the river if she run out of energy.The initially energy of cici is energy of the cheese at the coordinate (0,0).
CiCi只能有如图片中标示出来的4种走法(我开始就没明白这4种具体是什么)… 她每走一步都要消耗掉一定的体力。但是在每个格子中都有奶酪,CiCi一旦到达那个格子就可以通过食用奶酪得到一定的体力。他(CiCi究竟是男生还是女生?总不至于说还能变性吧?…)将无法到达河边如果她消耗完所有的体力。CiCi初始的体力等于格子(0,0)中的奶酪的能力值值。
if when the mouse arrive a position has 0 energy , he can't eat the cheese.
假如当老鼠到达某个格子的时候能量为0,那么他将不能吃这个奶酪。
Now can you help the wretched monse to calculate whether can he get to the river.
现在请你帮助这个悲惨的老鼠(应该是mouse吧?)计算她能否到达到河边。
If she can,calculate the minimun energy of the maximal energy of every possible position of the river(Y = N-1).
假如她可以,请计算她到河边的每个格子积累的最大能量值中的最小值。(这个表达可纠结…)(Y=N-1:又得吐槽几句,开始我真的压根儿没看懂这个表达式的意思……)
INPUT
There are several test cases.In each case,there are three integers n(0<n<=200),m(0<m<=10),and k(0<k<=10)in the first line ,the next n lines followed. The second line has only one integer c(0<c<=100),the i-th line has m integers more than (i-1)th line.
k is the energy each step cost.
有多组输入。在每种情况下,第一行是n,m,k,接下来有n行,第二行有一个整数c(真正纠结的地方来了,特地强调c这个变量是为了说明什么问题呢? 后来才知道只是为了说明这个是格子(0,0)的值,也就是CiCi的初始值…可是作者总该说明下的咯,题目都读了半天那!后来还是小朋友研究出来告诉我的…坑…)第i行的格子数总要比第i-1行的格子多m个。k是每走一步所要消耗的能量。
Output
If the monkey can not get to the river,print "what a pity mouse!!" int one line;If she can,calculate the minimun energy of the maximal energy of every possible position of the river(Y = N-1).
假如这个猴子(好了,这下不仅变性了,连本质都变了,老鼠变成猴子了说 = =|||)不能达到河边,请在一行中输出 "what a pity mouse!!";假如可以,请计算出她到河边的每个格子积累的最大能量值中的最小值。(Y=N-1)
-----------------------------------------------------------------------------------------------------------------------------------------------------------
好了,我们忽略文章中各种诡异的错误,认真分析问题,其实能发现这和之前的数塔问题本质是一样的。
本题注意点:(本着牺牲小我的精神,wa了3次…)
1、
long long min = INF_MAX;
for(i=0; i<1+(n-1)*m; ++i) if(min>dp[n-1][i]) min=dp[n-1][i];
if(min>0)
printf("%lld\n",min);
else
printf("what a pity mouse!!\n");
最后遍历dp[n-1][i]的时候想都没想,直接找最小值……
问题在于,在最后一行中有些点可能是无法到达的,意味着此时这些点可能值为非正。 如果不加判断的话,可能会增加无解的情况。
2、
#define MAXN 1010
int n, m, k, mat[210][MAXN];
long long dp[210][MAXN];
MAXN的值开的太小了,后来改成 -> #define MAXN 2020 就AC了…
观察数据,n(0<n<=200),m(0<m<=10),那么最后一行的值可能多达:200+10*200=2200,所以数组肯定要开大(这次这个应该叫险过…)
DP
1 memset(dp,0,sizeof(dp)); //很重要! 2 dp[0][0]=mat[0][0]; 3 for(i=0; i<n; ++i){ 4 for(j=0; j<1+i*m; ++j){ 5 if(dp[i][j]-k<=0) continue; 6 for(kk=0; kk<4; ++kk){ 7 tx = i+dx[kk]; 8 ty = j+dy[kk]; 9 if(tx>=n || ty>=tx*m+1) continue; 10 t = dp[i][j]-k+mat[tx][ty]; 11 if(t<=0) continue; 12 dp[tx][ty] = dp[tx][ty]>t ? dp[tx][ty] : t; 13 } 14 } 15 }
Output
1 //说真心的,这个代码写的真不喜欢… 又长又臭 2 long long min = INF_MAX; 3 bool flag=false; 4 for(i=0; i<1+(n-1)*m; ++i) { 5 if(dp[n-1][i]>0) { 6 flag = true; 7 break; 8 } 9 } 10 11 if(!flag){ 12 printf("what a pity mouse!!\n"); 13 continue; 14 } 15 16 for(i=0; i<1+(n-1)*m; ++i) { 17 if(dp[n-1][i]>0 && min>dp[n-1][i]) min = dp[n-1][i]; 18 } 19 printf("%lld\n",min);

浙公网安备 33010602011771号