Submission #704541

#TimeUsernameProblemLanguageResultExecution timeMemory
704541ByeWorldKangaroo (CEOI16_kangaroo)C++14
100 / 100
143 ms133652 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O1") #define int long long #define fi first #define se second #define pb push_back #define lb lower_bound #define ub upper_bound using namespace std; const int MAXN = 3e3+10; const double SMALL = 1e-6; const int INF = 5e5+10; const int MX = 2e12; const int MOD = 1e9+7; typedef pair<int,int> pii; typedef pair<pii,int> ipii; int sum(int a, int b){ return (a+b)%MOD; } int mul(int a, int b){ return (a*b)%MOD; } int dp[MAXN][MAXN][4]; // dp[id][cc] signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, S, T; cin >> n >> S >> T; dp[0][0][0] = 1; for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ if(i==S || i==T){ for(int k=0; k<=1; k++){ dp[i][j][k+1] = sum(dp[i-1][j-1][k], dp[i][j][k+1]); dp[i][j][k+1] = sum(dp[i-1][j][k], dp[i][j][k+1]); } continue; } for(int k=0; k<=2; k++){ dp[i][j][k] = sum(mul(dp[i-1][j-1][k], j-k), dp[i][j][k]); //dp[i][j][k] = sum(mul(dp[i-1][j][k], mul(2, j)-k), dp[i][j][k]); dp[i][j][k] = sum(mul(dp[i-1][j+1][k], j), dp[i][j][k]); } } } cout << dp[n][1][2]+dp[n][1][1]+dp[n][1][0] << '\n'; //cout << dp[n][1][2] << ' ' << dp[n][1][1] << ' ' <<dp[n][1][0] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...