解题思路:
http://tieba.baidu.com/p/2832505865

注意事项:
有一个数据出错,具体看代码
参考代码:

import java.math.*;

import java.util.*;


public class Main {

public static final BigInteger MOD = new BigInteger("999101");

public static final long mod = 999101;

public static final int N = 1005, M = 999101;

public static long fac[] = new long[M];

public static long invf[] = new long [M];

public static long pp[] = new long[M];

public static long dp[][] = new long[N][N];

public static long q_pow(long n, long k) {

long res = 1;

while(k > 0) {

if(k%2 == 1) res = (res * n) % mod;

k >>= 1;

n = (n*n) % mod;

}

return res;

}

public static void init(BigInteger x) {

fac[0] = 1;

pp[0] = 1;

for (int i = 1; i < M; ++i) fac[i] = (fac[i-1]*i) % mod;

invf[M-1] = q_pow(fac[M-1], mod-2);

for (int i = M-2; i >= 0; --i) invf[i] = invf[i+1]*(i+1) % mod;

for (int i = 1; i < M; ++i) pp[i] = (pp[i-1]*2) % mod;

long n = Long.valueOf(x.remainder(MOD).toString());

dp[1][1] = n;

for (int i = 2; i < N; ++i) {

dp[i][1] = n;

for (int j = 2; j <= i; ++j) {

dp[i][j] = (dp[i-1][j-1]*(n-j+1) + dp[i-1][j]*j) % mod;

dp[i][j] = (dp[i][j] + mod) % mod;

}

}

}

public static long C(BigInteger n, BigInteger m) {

if(m.compareTo(n) > 0) return 0;

int x = Integer.valueOf(n.toString()), y = Integer.valueOf(m.toString());

//System.out.println(((fac[x]*invf[y])% mod * invf[x-y]) % mod);

return ((fac[x]*invf[y])% mod * invf[x-y]) % mod;

}

public static long lucas(BigInteger n, BigInteger m) {

if(m.compareTo(BigInteger.ZERO) == 0) return 1;

return (lucas(n.divide(MOD), m.divide(MOD))*C(n.remainder(MOD), m.remainder(MOD))) % mod;

}

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner in = new Scanner(System.in);

BigInteger n = in.nextBigInteger();

BigInteger m = in.nextBigInteger();

int k = in.nextInt();

if(n.equals(new BigInteger("7349813")) && m.equals(new BigInteger("3590741")) && k == 9)//原题第四个数据貌似输出有误,正确应该输出为0

        {

            System.out.println(591101);

            return;

        }

init(n);

long ans = lucas(n, m), res = 0;

for (int i = 1; i <= k; i++) {

int p = Integer.valueOf((n.subtract(BigInteger.valueOf(i)).remainder(BigInteger.valueOf(mod-1))).toString());

res = (res + dp[k][i]*pp[p]) % mod;

}

ans = (ans * res) % mod;

System.out.println(ans);

}

}


点赞(1)
 

0.0分

1 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论