比赛 |
HAOI2009 模拟试题2 |
评测结果 |
AAAAATTTTT |
题目名称 |
着色方案 |
最终得分 |
50 |
用户昵称 |
lc |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2009-04-22 11:24:09 |
显示代码纯文本
- program ex1;
- const
- maxprime=199997;
- Inf=1000000007;
- var
- n,m: longint;
- ans: qword;
- now: integer;
- Ss,last,data: qword;
- color: array[1..15] of longint;
- state: array[0..1,0..maxprime] of record
- S,las: qword;
- end;
- tot: array[0..1] of qword;
- link,next: array[0..maxprime] of longint;
- sum: array[0..1,0..maxprime] of qword;
- cheng: array[0..16] of qword;
- anstate: qword;
-
-
- procedure Init;
- var
- i: longint;
- begin
- readln(m);
- for i :=1 to m do read(color[i]);
- for i :=1 to m do n :=n+color[i];
- cheng[0]:=1;
- for i :=1 to 16 do cheng[i] :=cheng[i-1]*6;
- end;
-
- procedure hash(Ss,last,data:qword);
- var
- t,pos: qword;
- begin
- data :=data mod Inf;
- t :=Ss mod maxprime; pos :=link[t];
- while pos <> 0 do begin
- if (state[now,pos].s=Ss) and (state[now,pos].las=last)
- then begin inc(sum[now,pos],data); sum[now,pos]:=sum[now,pos] mod Inf; exit end;
- pos :=next[pos];
- end;
- inc(tot[now]); pos :=tot[now];
- state[now,pos].s :=Ss; state[now,pos].las:=last; sum[now,pos] :=data ;
- next[pos] :=link[t]; link[t] :=pos;
- end;
-
-
- procedure Main;
- var
- i,j,k,L: longint;
-
- begin
- now :=0; hash(0,0,1);
- for i :=1 to m do anstate :=anstate+color[i]*cheng[i-1];
- for i :=1 to n do begin
- now :=1-now; tot[now] :=0;
- fillchar(link,sizeof(link),0);
- for k :=1 to tot[1-now] do begin
- Ss:=state[1-now,k].s; last :=state[1-now,k].las; data :=sum[1-now,k];
- data :=data mod Inf ;
- for L :=1 to m do if last<>L then
- if ((Ss div cheng[L-1]) mod 6<=color[L]) then
- hash(Ss+cheng[L-1],L,data);
- end;
- end;
-
- for k :=1 to tot[now] do begin
- Ss:=state[now,k].s; data :=sum[now,k];
- if Ss=anstate then ans :=(ans+data) mod Inf;
- end;
- writeln(ans);
- end;
-
-
- begin
- assign(input,'color.in'); reset(input);
- assign(output,'color.out'); rewrite(output);
- Init;
- Main;
- close(input); close(output);
- end.