| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
很简单的,为什么会MLE,帮忙指正,无限感激!题目:http://acm.nankai.edu.cn/p1703.html
我用的内存也不多啊,就是一个队列,长度小于30,还有一个数组a[maxsize<=30]
我的代码:
#include <cstdlib>
#include <iostream>
#include<queue>
using namespace std;
int main(int argc, char *argv[])
{
int maxsize;
queue<int> q;
int num;
char ch;
int icnt = 1;
while(1)
{
cin>>num;
q.push(num);
if(num>maxsize)
maxsize = num;
ch = cin.get();
if(ch==EOF)
break;
}
long *a = new long[maxsize];
for(int i = 0; i<maxsize; i++)
{a[i] = 0;}
a[0] = a[1] = 1;
for(int i = 2; i<maxsize; i++)
{
for(int j = 0; j<i; j++)
{
a[i] += a[j]*a[i-1-j];
}
}
while(!q.empty())
{
cout<<"Case "<<icnt<<":"<<endl;
cout<<a[q.front()]<<endl;
icnt++;
q.pop();
}
delete []a;
//system("PAUSE");
return EXIT_SUCCESS;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator