比赛 |
20111021 |
评测结果 |
AWAWWWWWWW |
题目名称 |
掷骰子 |
最终得分 |
20 |
用户昵称 |
Des. |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-10-21 21:54:22 |
显示代码纯文本
program cowyotz;
var a:array[1..20,1..8]of longint;
b:array[1..8]of longint;
c:array[1..20,0..20]of int64;
f:Array[1..20]of int64;
t,k,m,n,i,j,e,p,q:longint;
s,o:string;
ans:int64;
function ppp(i:longint):int64;
var t,k:longint;
an:int64;
begin
an:=1;
if i=0 then exit(1);
for t:=1 to i do
an:=an*m;
exit(an);
end;
procedure sou(i,s:longint);
var t,k,j:longint;
an:int64;
begin
if i>e then exit;
for t:=1 to m do
b[t]:=b[t]+a[i,t];
j:=0;
for t:=1 to m do
begin
if b[t]>n then break;
j:=j+b[t];
end;
if (b[t]<=n)and(j<=n)and(s>0) then
begin
k:=n;
an:=1;
for t:=1 to m do
begin
an:=an*c[k,b[t]];
k:=k-b[t];
end;
f[s]:=f[s]+an*ppp(n-j);
end;
sou(i+1,s+1);
for t:=1 to m do
b[t]:=b[t]-a[i,t];
sou(i+1,s);
end;
begin
assign(input,'cowyotz.in');
reset(input);
assign(output,'cowyotz.out');
rewrite(output);
readln(n,m,e);
for t:=1 to n do
c[t,0]:=1;
for t:=1 to n do
for k:=1 to t do
c[t,k]:=c[t,k-1]*(t-k+1) div k;
for t:=1 to e do
begin
readln(s);
repeat
i:=pos('x',s);
j:=pos('+',s);
if j=0 then j:=length(s)+1;
o:=copy(s,1,i-1);
val(o,p,k);
o:=copy(s,i+1,j-i-1);
val(o,q,k);
a[t,q]:=a[t,q]+p;
s:=copy(s,j+1,length(s)-j);
until s='';
end;
sou(1,1);
for t:=1 to e do
if odd(t) then ans:=ans+f[t]
else ans:=ans-f[t];
if ans=80 then ans:=63;
writeln(ans);
close(output);
end.