#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef LOCAL
#define debug(...) __VA_ARGS__
#else
#define debug(...) {}
#endif
set<vector<int> > dobre[3001];
int n,m;
void sprawdz(vector<int> a, int x){
if (int(a.size()) == x){
for (int j = 1; j < x; j++){
vector<int> ax;
vector<int> ay;
for (int k = 0; k < j ; k++) ax.push_back(a[k]);
for (int k = j; k < x; k++) ay.push_back(a[k]);
if (dobre[j].find(ax) != dobre[j].end() && dobre[x-j].find(ay) != dobre[x-j].end()){
dobre[x].insert(a);
return;
}
}
if (a[0] == a[x-1]){
dobre[x].insert(a);
}
return;
}
for (int j = 1; j < m+1 ; j++){
vector<int> akt;
for (int k : a) akt.push_back(k);
akt.push_back(j);
sprawdz(akt,x);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for (int j = 2; j < n+1; j++){
sprawdz({},j);
}
cout<<dobre[n].size()<<"\n";
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #include <bits/stdc++.h> using namespace std; typedef long long ll; #ifdef LOCAL #define debug(...) __VA_ARGS__ #else #define debug(...) {} #endif set<vector<int> > dobre[3001]; int n,m; void sprawdz(vector<int> a, int x){ if (int(a.size()) == x){ for (int j = 1; j < x; j++){ vector<int> ax; vector<int> ay; for (int k = 0; k < j ; k++) ax.push_back(a[k]); for (int k = j; k < x; k++) ay.push_back(a[k]); if (dobre[j].find(ax) != dobre[j].end() && dobre[x-j].find(ay) != dobre[x-j].end()){ dobre[x].insert(a); return; } } if (a[0] == a[x-1]){ dobre[x].insert(a); } return; } for (int j = 1; j < m+1 ; j++){ vector<int> akt; for (int k : a) akt.push_back(k); akt.push_back(j); sprawdz(akt,x); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for (int j = 2; j < n+1; j++){ sprawdz({},j); } cout<<dobre[n].size()<<"\n"; return 0; } |
English