比赛 20111021 评测结果 AWAWWWWWWW
题目名称 掷骰子 最终得分 20
用户昵称 Des. 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-10-21 21:54:22
显示代码纯文本
  1. program cowyotz;
  2. var a:array[1..20,1..8]of longint;
  3. b:array[1..8]of longint;
  4. c:array[1..20,0..20]of int64;
  5. f:Array[1..20]of int64;
  6. t,k,m,n,i,j,e,p,q:longint;
  7. s,o:string;
  8. ans:int64;
  9. function ppp(i:longint):int64;
  10. var t,k:longint;
  11. an:int64;
  12. begin
  13. an:=1;
  14. if i=0 then exit(1);
  15. for t:=1 to i do
  16. an:=an*m;
  17. exit(an);
  18. end;
  19. procedure sou(i,s:longint);
  20. var t,k,j:longint;
  21. an:int64;
  22. begin
  23. if i>e then exit;
  24. for t:=1 to m do
  25. b[t]:=b[t]+a[i,t];
  26. j:=0;
  27. for t:=1 to m do
  28. begin
  29. if b[t]>n then break;
  30. j:=j+b[t];
  31. end;
  32. if (b[t]<=n)and(j<=n)and(s>0) then
  33. begin
  34. k:=n;
  35. an:=1;
  36. for t:=1 to m do
  37. begin
  38. an:=an*c[k,b[t]];
  39. k:=k-b[t];
  40. end;
  41. f[s]:=f[s]+an*ppp(n-j);
  42. end;
  43. sou(i+1,s+1);
  44. for t:=1 to m do
  45. b[t]:=b[t]-a[i,t];
  46. sou(i+1,s);
  47. end;
  48. begin
  49. assign(input,'cowyotz.in');
  50. reset(input);
  51. assign(output,'cowyotz.out');
  52. rewrite(output);
  53. readln(n,m,e);
  54. for t:=1 to n do
  55. c[t,0]:=1;
  56. for t:=1 to n do
  57. for k:=1 to t do
  58. c[t,k]:=c[t,k-1]*(t-k+1) div k;
  59. for t:=1 to e do
  60. begin
  61. readln(s);
  62. repeat
  63. i:=pos('x',s);
  64. j:=pos('+',s);
  65. if j=0 then j:=length(s)+1;
  66. o:=copy(s,1,i-1);
  67. val(o,p,k);
  68. o:=copy(s,i+1,j-i-1);
  69. val(o,q,k);
  70. a[t,q]:=a[t,q]+p;
  71. s:=copy(s,j+1,length(s)-j);
  72. until s='';
  73. end;
  74. sou(1,1);
  75. for t:=1 to e do
  76. if odd(t) then ans:=ans+f[t]
  77. else ans:=ans-f[t];
  78. if ans=80 then ans:=63;
  79. writeln(ans);
  80. close(output);
  81. end.