首页 > vijos > vijos_1080

vijos_1080

2009年11月4日 moradin 发表评论 阅读评论

Function(Function(F…-20min-搜索

Hint

1、判定“-1 -1 -1”出错
2、该函数事实上满足w[a,a,a]:=2^a;当 (a<=b) or (a<=c) 时 w:=2^a
3、根本不用在前面加判断,直接把函数值赋给数组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var a,b,c:longint;
    m:array[0..20,0..20,0..20] of longint;
function w(a,b,c:longint):longint;
var p,q,r,s:longint;
begin
  if (a<=0)or(b<=0)or(c<=0)
    then w:=1
    else
      if (a>20)or(b>20)or(c>20)
        then
          if m[20,20,20]<>0 then w:=m[20,20,20]
                            else w:=w(20,20,20)
        else
          if (a<b)and(b<c)
            then begin
                   if m[a,b,c-1]<>0 then p:=m[a,b,c-1]
                                    else p:=w(a,b,c-1);
                   if m[a,b-1,c-1]<>0 then q:=m[a,b-1,c-1]
                                      else q:=w(a,b-1,c-1);
                   if m[a,b-1,c]<>0 then r:=m[a,b-1,c]
                                    else r:=w(a,b-1,c);
                   w:=p+q-r;
                   m[a,b,c]:=p+q-r;
                 end
            else begin
                   if m[a-1,b,c]<>0 then p:=m[a-1,b,c]
                                    else p:=w(a-1,b,c);
                   if m[a-1,b-1,c]<>0 then q:=m[a-1,b-1,c]
                                      else q:=w(a-1,b-1,c);
                   if m[a-1,b,c-1]<>0 then r:=m[a-1,b,c-1]
                                      else r:=w(a-1,b,c-1);
                   if m[a-1,b-1,c-1]<>0 then s:=m[a-1,b-1,c-1]
                                        else s:=w(a-1,b-1,c-1);
                   w:=p+q+r-s;
                   m[a,b,c]:=p+q+r-s;
                 end;
end;
begin
  readln(a,b,c);
  while not((a=-1)and(b=-1)and(c=-1)) do begin
    writeln('w(',a,', ',b,', ',c,') = ',w(a,b,c));
    readln(a,b,c);
  end;
end.

编译通过…
├ 测试数据 01:答案正确… 0ms
————————-
Accepted 有效得分:100 有效耗时:0ms

分类: vijos 标签: , ,
  1. 2009年11月4日23:11 | #1

    要学会用exit(x)这个东西…….
    function solve(a,b,c :longint):longint;
    begin
    if(a<=0)or(b<=0)or(c20)or(b>20)or(c>20)then exit(solve(20,20,20));
    if f[a,b,c]>0 then exit(f[a,b,c]);
    if(a<b)and(b<c)then
    f[a,b,c]:=solve(a,b,c-1)+solve(a,b-1,c-1)-solve(a,b-1,c)
    else
    f[a,b,c]:=solve(a-1,b,c)+solve(a-1,b-1,c)+
    solve(a-1,b,c-1)-solve(a-1,b-1,c-1);
    exit(f[a,b,c]);
    end; { solve }

  2. moradin
    2009年11月5日21:31 | #2

    @Wandsea RP++,长见识……

  1. 本文目前尚无任何 trackbacks 和 pingbacks.
评论头像:请点击注册,可用于所有wordpress的评论
注意: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。使用'@all ',将会将评论发送给之前所有其它评论者。请务必注意user必须和评论者名相匹配(大小写一致)。