60分,MLE+WA
查看原帖
60分,MLE+WA
566200
Fire_Raku楼主2022/5/16 20:46

求助,

#include<bits/stdc++.h>
using namespace std ;
int t , n , p , x , y , ans , dp[10001][10001] ; 
int main(){
	cin >> t ; 
	while(t--){
		dp[1][1] = 1 ;  
		ans = 0 ; 
		cin >> n >> p >> x >> y ; 
		if(x == y){
			if((x * n) % p != 0) cout << 1 << endl ; 
			else cout << 0 << endl ;  
		}
		else{
			for(int i = 1 ; i <= n + 1 ; i++){ 
				for(int j = 1 ; j + i <= n + 2 ; j++){ 
					if(i == 1 && j == 1) continue ; 
					if((x * (i - 1) + y * (j - 1)) % p == 0) dp[i][j] = 0 ; 
					else dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007 ; 
					if(j + i == n + 2) ans = (ans + dp[i][n - i + 2]) % 1000000007 ; 
				} 
			}
			cout << ans % 1000000007 << endl ; 
		}
	}
	return 0 ; 
}
2022/5/16 20:46
加载中...