洛谷 P1311 选择客栈

题目传送门

带系数的杨辉三角,用换元法(t = ax,s = by),求((t+s)^k)之后带回去,求得系数.

#include<iostream>
#include<cstdio>
#include<cstring>
#define mod 10007

using namespace std;

long long a,b,k,n,m;
long long xs[1001][1001];

inline long long pow(long long x,long long y) {
	long long res = 1,kk = x;
	while(y) {
		if(y % 2 == 1) res = res * kk % mod;
		kk = kk * kk % mod;
		y >>= 1;
	}
	return res;
}

int main() {
	scanf("%lld%lld%lld%lld%lld",&a,&b,&k,&n,&m);
	a = pow(a,n) * pow(b,m) % mod;
	xs[1][1] = xs[1][2] = 1;
	xs[2][1] = xs[2][3] = 1;
	xs[2][2] = 2;
	for(int i = 3;i <= k; i++) {
		for(int j = 2;j <= i; j++)
			xs[i][j] = (xs[i-1][j-1] + xs[i-1][j]) % mod;
		xs[i][1] = xs[i][i+1] = 1;
	}
	printf("%lld",((a % mod) * (xs[k][m+1] % mod)) % mod);
	return 0;
}
原文地址:https://www.cnblogs.com/lipeiyi520/p/13837365.html