我已经记忆化过了,为什么还是TLE
查看原帖
我已经记忆化过了,为什么还是TLE
755270
jzc114514楼主2024/1/25 14:21

求助!

#include <iostream>
#include <cstdio>
using namespace std;int n,m;
long long s[31][31];
long long d(int a,int b){
//	if(a==m-1)return 1;
 	if(a==m-1){
 		if(b==2||b==n)return 1;
 		return 0;
 	}
	if(s[a][b])return s[a][b];
	s[a][b]=d(a+1,b%n+1)+d(a+1,b!=1?b-1:n);
	return s[a][b];
}
int main(){
	cin>>n>>m;
	cout<<d(1,2)+d(1,n);
} 


这道题应该用递归做吗?

2024/1/25 14:21
加载中...