이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |