제출 #870071

#제출 시각아이디문제언어결과실행 시간메모리
870071Pichon5캥거루 (CEOI16_kangaroo)C++17
100 / 100
22 ms31600 KiB
#include <bits/stdc++.h> #include <iostream> #include <vector> #include <algorithm> #include <string> #include <cmath> #include <set> #include <map> #include <queue> #include <stack> #include <sstream> #define fvoices ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define vi vector<int> #define sz(x) (int)x.size() #define all(x) x.begin(),x.end() #define S second #define F first #define pb push_back #define rep(i,a,b) for(int i=a;i<b;i++) #define pii pair<int,int> #define vii vector<pii> #define endl '\n' #define int long long #define ll long long using namespace std; const int tam=2005; int dp[tam][tam]; const int MOD=1e9 +7; int add(int a, int b){ return (a%MOD+b%MOD)%MOD; } int mul(int a, int b){ return (a%MOD*b%MOD)%MOD; } signed main(){ int n,a,b; cin>>n>>a>>b; // inicio en a termino en b dp[1][1]=1;// [elementos][chunks] for(int i=2;i<=n;i++){ for(int l=1;l<=n;l++){ if(i==a or i==b){ dp[i][l]=add(dp[i-1][l-1],dp[i-1][l]); continue; } // crear un nuevo chunk int espacios=l - (i>a) - (i>b); if(espacios<0)espacios=0; dp[i][l]=mul(espacios,dp[i-1][l-1]); // unir chunks dp[i][l]=add(dp[i][l],mul(l,dp[i-1][l+1])); } } cout<<dp[n][1]<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...