Logo Wy Online Judge

WyOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#536#115. 【0621 模拟赛】Bojanjeryp10050ms3860kbC++142.3kb2025-06-20 09:53:542025-06-21 23:21:17

answer


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
int n, t, k, inv, a[15], sum[45], H, T, now, S, res, num[45], cnt[15], tem, tt;
map<int, int>f;
struct martix{
	int a[45][45];
	martix(){
		memset(a, 0, sizeof(a));
	}
	inline void init(){
		for(int i = 1; i <= T; i++) a[i][i] = 1;
	}
	inline void print(){
		for(int i = 1; i <= T; i++){
			for(int j = 1; j <= T; j++){
				printf("%lld ", a[i][j]);
			}
			putchar('\n');
		}
	}
}base, ans;
inline int qp(int x, int y){
	int res = 1;
	while(y){
		if(y & 1) res = res * x % mod;
		x = x * x % mod, y >>= 1;
	}
	return res;
}
inline martix operator * (martix x, martix y){
	martix res;
	for(int i = 1; i <= T; i++){
		for(int k = 1; k <= T; k++){
			if(x.a[i][k] == 0) continue ;
			for(int j = 1; j <= T; j++){
				res.a[i][j] += x.a[i][k] * y.a[k][j] % mod;
				res.a[i][j] %= mod;
			}
		}
	}
	return res;
}
inline int calc(int x){
	S = 0; 
	for(int i = 1; x; i++){
		cnt[i] = x % 10;
		S++;
		x /= 10;
	}
	now = 0;
	for(int i = 1; i <= S; i++){
		for(int j = 1; j <= cnt[i]; j++){
			a[++now] = i;
		}
	}
	return S;
}
inline int work(){
	for(int i = 1; i <= 10; i++) sum[i] = 0;
	for(int i = 1; i <= n; i++) sum[a[i]]++;
	int res = 0;
	sort(sum + 1, sum + 11);
	for(int i = 1; i <= 10; i++){
		res = res * 10 + sum[i];
	}
	return res;
}
inline void bfs(){
	for(int i = 1; i <= n; i++) a[i] = i;
	tem = work();
	f[tem] = 1;
	num[T = 1] = tem;
	while(H < T){
		H++;
		calc(num[H]);
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				tt = a[j];
				a[j] = a[i];
				tem = work();
				if(f[tem] == 0){
					f[tem] = ++T;
					num[T] = tem;
				}
				base.a[H][f[tem]]++;
				a[j] = tt;
			}
		}
	}
}
inline martix ksm(martix x, int y){
	martix res;
	res.init();
	while(y){
		if(y & 1) res = res * x;
		x = x * x, y >>= 1;
	}
	return res;
}
signed main(){
	scanf("%lld%lld%lld", &n, &t, &k);
	inv = qp(n * n, mod - 2);
	bfs();
	for(int i = 1; i <= T; i++) for(int j = 1; j <= T; j++) base.a[i][j] = base.a[i][j] * inv % mod;
	base = ksm(base, t);
	ans.a[1][1] = 1;
	ans = ans * base;
	for(int i = 1; i <= T; i++){
		if(calc(num[i]) >= k){
			res += ans.a[1][i];
			res %= mod;
		}
	}
	printf("%lld", res);
	return 0;
} 

Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 28
Accepted

Test #1:

score: 28
Accepted
time: 2ms
memory: 3816kb

input:

8 1 8

output:

125000001

result:

ok "125000001"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3504kb

input:

9 2 9

output:

123456791

result:

ok "123456791"

Test #3:

score: 0
Accepted
time: 2ms
memory: 3724kb

input:

2 298410478936087415 2

output:

570941114

result:

ok "570941114"

Test #4:

score: 0
Accepted
time: 2ms
memory: 3740kb

input:

5 576602506791120693 5

output:

624640657

result:

ok "624640657"

Test #5:

score: 0
Accepted
time: 13ms
memory: 3532kb

input:

10 256228184114116456 10

output:

325844394

result:

ok "325844394"

Subtask #2:

score: 36
Accepted

Test #6:

score: 36
Accepted
time: 1ms
memory: 3724kb

input:

5 2 3

output:

1

result:

ok "1"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

3 565 2

output:

446411373

result:

ok "446411373"

Test #8:

score: 0
Accepted
time: 1ms
memory: 3836kb

input:

8 377 3

output:

121415859

result:

ok "121415859"

Test #9:

score: 0
Accepted
time: 2ms
memory: 3812kb

input:

9 840 8

output:

165318551

result:

ok "165318551"

Test #10:

score: 0
Accepted
time: 4ms
memory: 3764kb

input:

10 936 4

output:

611789290

result:

ok "611789290"

Subtask #3:

score: 36
Accepted

Test #11:

score: 36
Accepted
time: 0ms
memory: 3860kb

input:

6 607026166077649625 5

output:

312920168

result:

ok "312920168"

Test #12:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

7 125452864890658981 2

output:

815023468

result:

ok "815023468"

Test #13:

score: 0
Accepted
time: 4ms
memory: 3588kb

input:

8 511066077813606532 4

output:

283063302

result:

ok "283063302"

Test #14:

score: 0
Accepted
time: 6ms
memory: 3692kb

input:

9 570632528518075962 5

output:

348914172

result:

ok "348914172"

Test #15:

score: 0
Accepted
time: 12ms
memory: 3660kb

input:

10 294082151269059690 8

output:

69248946

result:

ok "69248946"