This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 2000000000
#define INFLL 1000000000000000000LL
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll DIV = 1000000007;
const int MAX_N = 3000;
int N, K;
ll dp[2][MAX_N+1];
int main(){
scanf("%d%d", &N, &K);
dp[0][0] = 1;
for(int i=1; i<N; i++){
for(int j=0; j<i; j++){
dp[1][j] = (dp[1][j] + dp[0][j] * (ll)(j+1)) % DIV;
dp[1][j+1] = (dp[1][j+1] + dp[0][j] * (ll)(i-j)) % DIV;
}
for(int j=0; j<=i; j++){
dp[0][j] = dp[1][j]; dp[1][j] = 0;
//cout<<i+1<<" "<<j<<" "<<dp[0][j]<<endl;
}
}
printf("%lld", dp[0][K-1]);
return 0;
}
Compilation message (stderr)
asceticism.cpp: In function 'int main()':
asceticism.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &K);
~~~~~^~~~~~~~~~~~~~~~
# | 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... |