讨论 / 总感觉有些地方不太对。神牛进下~
L.Lawliet 2010-11-11 05:17:00
点我顶贴 收藏 删除
写了个2维费用DP 不知这样写是否标准。

马马虎虎就提交了。没想到AC了

可是我还是觉得有些地方不太对。

比如赋值的判断 万一mty可以耗费大量的时间干掉敌人呢?有没有可能输出错误的?

希望大牛出点NB的数据。或者解释下为什么能A?

f[i]表示去掉对手iHP的最短时间

h[i]表示去掉对手iHP的最多剩余HP

h的优先级低于f 也就是说在时间相同的情况下才对h进行更新。

const maxn=100;

var f,h:array[0..maxn]of longint;

i,j,k,m,n,p,x,y:longint;

begin

readln(n,m,p);

for i:=0 to n do

begin

f[i]:=maxlongint;

h[i]:=-maxlongint;

end;

f[0]:=0;

h[0]:=m;

for p:=1 to p do

begin

readln(x,y);

for i:=x to n do

begin

if h[i-x]<=y then continue;

[color=red]if (f[i-x]+1<f[i])or((f[i-x]+1=f[i])and(h[i-x]-y>h[i])){就是这里了。}[/color] then

begin

f[i]:=f[i-x]+1;

h[i]:=h[i-x]-y;

end;

end;

end;

if f[n]<maxint then

writeln(f[n])

else writeln('mty zhen mei yong!');

end.

附时间:

题目:mty的格斗

状态: [color=green]Accepted[/color]

测评机: Xeost[5]

得分: 100分

提交日期: 2010-11-11 17:38:00

有效耗时: 1594毫秒

测试结果1: [color=green]通过本测试点|有效耗时156ms [/color]

测试结果2: [color=green]通过本测试点|有效耗时157ms [/color]

测试结果3: [color=green]通过本测试点|有效耗时156ms [/color]

测试结果4: [color=green]通过本测试点|有效耗时187ms [/color]

测试结果5: [color=green]通过本测试点|有效耗时157ms [/color]

测试结果6: [color=green]通过本测试点|有效耗时156ms[/color]

测试结果7: [color=green]通过本测试点|有效耗时156ms [/color]

测试结果8: [color=green]通过本测试点|有效耗时156ms [/color]

测试结果9: [color=green]通过本测试点|有效耗时157ms [/color]

测试结果10: [color=green]通过本测试点|有效耗时156ms [/color]

#1 zhongjiaxin@2010-11-11 02:40:00
回复 删除
哪题

#2 L.Lawliet@2010-11-11 05:17:00
回复 删除
真正的二维费用背包需要建三维数组 可我只建了两个一维数组 求证解法正确性~
查看更多回复
提交回复