nowcoder acm contest 5881 B 莫得難題

題目描述

自己看

通俗易懂

下面是lkp的想法

()¥#)@()&%()@¥#()&¥#&@()#%&%
&¥#……%@#¥#@¥@%&

題解

我們可以看出一位數有5 個兩位數有25個
n位數有5^n個, 顯然我們可以推出
我們對 \(C_n^m\)得到的數,不斷地%5 /5
對每一次%5 得到的餘數就是答案

code

#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>

#define int long long
#define rr register

#define inf 1e9
#define MAXN 100010

using namespace std;

inline int read(int &T) {
	int s = 0, f = 0;
	char ch = getchar();
	while (!isdigit(ch)) f |= ch == '-', ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return T = f ? -s : s;
}

const int mod = 1e9 + 7;

void print(int x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) print(x / 10);
	putchar(x % 10 + 48);
}

int t, n, m;

int a[10];

int c[200][200];

inline int init() {
    a[1] = 1;
    a[2] = 2;
    a[3] = 3;
    a[4] = 5;
    a[0] = 9;
	for (rr int i = 0; i <= 100; i++) c[i][0] = 1;
	for (rr int i = 1; i <= 100; i++)
		for (rr int j = 1; j <= 100; j++) 
			c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
}

void pr(int x) {
	if (x > 5) {
		if (x % 5 != 0)
			pr(x / 5);
		else pr(x / 5 - 1);
	}
	cout << a[x % 5]; 
}

signed main() {
	init();
	t = read(t);
	while (t--) {
		n = read(n);
		m = read(m);
		pr(c[n][m]);
		puts("");
	}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章