比赛 |
20110729 |
评测结果 |
AEEEEEEEEE |
题目名称 |
sumcount |
最终得分 |
10 |
用户昵称 |
reamb |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-07-29 11:48:41 |
显示代码纯文本
program fangchengdejie;
var
n,i,j,a,b,p,sum:longint;
c:array[1..100,0..100]of int64;
jc:array[0..100]of int64;
function max(a,b:longint):longint;
begin
if a>b then
max:=a
else
max:=b
end;
function jie(k:longint):longint;
var
l,z:longint;
begin
z:=0;
if n>=k then
for l:=n-k to n-1 do
z:=(z+c[n,l]*c[i-1,n-l-1])mod p
else
for l:=0 to n-1 do
z:=(z+c[n,l]*c[i-1,n-l-1])mod p;
exit(z)
end;
begin
assign (input,'sumcount.in');
reset (input);
assign (output,'sumcount.out');
rewrite (output);
readln (n,a,b,p);
c[n,0]:=1;
jc[0]:=1;
for i:=1 to max(n,b) do
jc[i]:=jc[i-1]*i;
for i:=1 to n do
c[n,i]:=jc[n]div(jc[i]*jc[n-i]);
c[a-1,0]:=1;
for i:=1 to a-1 do
c[a-1,i]:=jc[a-1]div(jc[i]*jc[a-1-i]);
for i:=a to b do
begin
c[i,0]:=1;
for j:=1 to i do
c[i,j]:=jc[i]div(jc[j]*jc[i-j]);
sum:=(sum+jie(i))mod p
end;
writeln (sum);
close (input);
close (output)
end.