QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682532#9254. Random Variablesforgive_WA 2ms22312kbC++141.2kb2024-10-27 15:53:082024-10-27 15:53:08

Judging History

你现在查看的是最新测评结果

  • [2024-10-27 15:53:08]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:22312kb
  • [2024-10-27 15:53:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std ;

typedef long long LL ;
const int N = 2010 ;
int mod ;

LL ksm( LL a , LL b )
{
	LL res = 1 , t = a % mod ;
	while( b ) {
		if( b&1 ) res = res * t % mod ;
		b = b >> 1 ;
		t = t * t % mod ;
	}
	return res ;
}
int t , n , M , K ;
LL C[N][N] , f[N][N] ;
int vis[N][N] ;
void pre_work( int n )
{
	for(int i = 0 ; i <= n ; i ++ ) {
		C[i][0] = 1 ;
		for(int j = 1 ; j <= i ; j ++ ) {
			C[i][j] = ( C[i-1][j] + C[i-1][j-1] ) % mod ;
		}
	}
}
LL dp( int n , int m ) // n个不同小球放入 m 个箱子,要求每个箱子中球数 <= K 
{
	if( n < 0 ) return 0 ;
	if( m == 1 ) return (n<=K) ;
	if( n == 0 ) return 1 ;
	if( vis[n][M-m] == K ) return f[n][M-m] ;
	vis[n][M-m] = K ;
	return f[n][M-m] = m*( dp(n-1,m) - dp(n-K-1,m-1)*C[n-1][K]%mod ) % mod ;
}

int main()
{
	scanf("%d%d" , &t , &mod ) ;
	pre_work(1000) ;
	while( t -- ) {
		scanf("%d%d" , &n , &M ) ;
		for(int i = 0 ; i <= n ; i ++ ) {
			for(int j = 0 ; j <= n ; j ++ ) vis[i][j] = 0 ;
		}
		LL ans = 0 , pw = ksm(M,n) ;
		for( K = 0 ; K <= n ; K ++ ) {
			ans = ( ans + pw - dp(n,M) ) % mod ;
		}
		printf("%lld\n" , (ans+mod)%mod ) ;
	}
	return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 20228kb

input:

3 123456789
3 2
5 5
7 7

output:

18
7145
2066323

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 22312kb

input:

100 2
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
2 1
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
4 1
4 2
4 3
4 4
4 5
4 6
4 7
4 8
4 9
4 10
5 1
5 2
5 3
5 4
5 5
5 6
5 7
5 8
5 9
5 10
6 1
6 2
6 3
6 4
6 5
6 6
6 7
6 8
6 9
6 10
7 1
7 2
7 3
7 4
7 5
7 6
7 7
7 8
7 9
7 10
8 1
8 2...

output:

1
0
1
1
1
1
1
1
1
1
0
0
0
1
0
1
0
1
0
1
1
0
1
1
1
1
1
1
1
1
0
0
0
1
0
1
0
1
0
1
1
0
1
1
1
1
1
1
1
1
0
0
0
1
0
1
0
1
0
1
1
0
1
1
1
1
1
1
1
1
0
0
0
1
0
1
0
1
0
1
1
0
1
1
1
1
1
1
1
1
0
0
0
1
0
1
0
1
0
1

result:

wrong answer 4th lines differ - expected: '0', found: '1'