# 两种思路

const p=10007;maxk=1000;
var a,b,k,n,m:longint;
function C(k,m:longint):longint;
var f:array[0..maxk,0..maxk] of longint;
i,j,n:longint;
begin
n:=k-m;
if(n=0)or(m=0)then exit(1);
for i:=0 to n do f[i][0]:=1;
for j:=0 to m do f[0][j]:=1;
for i:=1 to n do
for j:=1 to m do
f[i][j]:=(f[i-1][j]+f[i][j-1])mod p;
exit(f[n][m]);
end;
function exp(a,b:longint):longint;
var ans,temp:int64;
begin
ans:=1;temp:=a;
while b<>0 do
begin
if((b and 1)=1)then ans:=(ans*temp)mod p;
temp:=(temp*temp)mod p;
b:=b shr 1;
end;
exit(ans);
end;
begin
if(n=0)and(m=0)
then begin
writeln(0);
halt;
end;
a:=a mod p;b:=b mod p;
writeln(C(k,m)*int64(exp(a,n))*exp(b,m) mod p);
end.

var
f:array[-1..1001,-1..1001] of longint;
a,b,m,n,k,i,j:longint;
begin
f[1,0]:=b;
f[1,1]:=a;
for i:=2 to k do
for j:=0 to k do
f[i,j]:=(f[i-1,j]*b+f[i-1,j-1]*a) mod 10007;
writeln(f[k,n]);
end.

# 6 条评论

• @ 2016-08-14 21:55:20

杨辉三角或者组合恒等式都能推

• @ 2014-11-05 21:25:11

这是二项式定理？

• @ 2014-11-04 07:33:56

你可以去看一下杨辉三角 这种令中国人骄傲的定理一定要懂啊

• @ 2014-11-03 20:14:33

我是twd2的追随者

• @ 2014-11-03 20:07:14

agreed

• @ 2014-11-03 20:04:49

详见数学选修课本

• 1

ID
1739

6

3862

1095

28%

15