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>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
const int mod=1e9+7, maxn=1e4+5;
int n, s, e;
ll res, memo[100][10][2];
ll dp(int mask, int node, int arah) {
if(__builtin_popcount(mask)==n) {
if(node==e) return 1;
return 0;
}
if(memo[mask][node][arah]!=-1) return memo[mask][node][arah];
ll ans=0;
if(arah) {
for(int i=node+1; i<=n; i++) {
if(((1<<(i-1))&mask)==0) ans=(dp(mask|(1<<(i-1)), i, 1-arah)+ans)%mod;
}
} else {
for(int i=node-1; i>0; i--) {
if(((1<<(i-1))&mask)==0) ans=(dp(mask|(1<<(i-1)), i, 1-arah)+ans)%mod;
}
}
memo[mask][node][arah]=ans;
return ans;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> s >> e;
memset(memo, -1, sizeof(memo));
res=dp(1<<(s-1), s, 0);
memset(memo, -1, sizeof(memo));
res=(res+dp(1<<(s-1), s, 1))%mod;
cout << res << '\n';
}
# | 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... |