//题目是总共n长度,每次可走1~m步,但不能跟上次和上上次步长相同,求总共走法 //超时了,只过了40% void back(int& cnt, int lastlast, int last, int left, int m) { if (left == 0) { ++cnt; return; } for (int i = 1; i <= m; ++i) { if (i > left) break; if (i == lastlast || i == last) continue; left -= i; back(cnt, last ,i, left, m); left += i; } } int main() { int n, m; cin >> n >> m; int cnt = 0; int ll = -1, l = -1; back(cnt, ll,l , n, m); cout << cnt; return 0; }
全部评论
(0) 回帖