请问为什么会MLE
查看原帖
请问为什么会MLE
217155
zhyz18cm楼主2020/11/16 19:32

用递归的思想暴力求解,但不知道为什么会MLE,球球各位大佬帮蒟蒻看看了

#include<iostream>
using namespace std;
int n;
int a[25]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608};
int aaa(int x)
{
	for(int i=1;i<=23;i++)
	{
		if(a[i]>n)
		{
			cout<<a[i-1]<<" ";
			n-=a[i-1];
			break;
		}
		if(a[i]==n)
		{
			cout<<a[i];
			return 0;
		}
	}
	aaa(n);
}
int main()
{
	cin>>n;
	if(n%2!=0)
	{
		cout<<"-1";
		return 0;
	}
	aaa(n);
 } 
2020/11/16 19:32
加载中...