| ||||||||||
| 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 | |||||||||
记忆化,谁能告诉我哪里错了? 思路很清晰的#include <iostream>
using namespace std;
int res[1010];
int array[1010];
int mark[1010];
int len;
int func(int index)
{
if(res[index] >= 0)
return res[index];
int max = 0;
int t;
for(int i = 0;i < index;i++)
{
t = func(i);
if(array[index] > mark[i])
{
t ++;
if(t > max)
{
max = t;
mark[index] = array[index];
}
}
else
{
if(t > max)
{
max = t;
mark[index] = mark[i];
}
}
}
return res[index] = max;
}
int main()
{
while(scanf("%d",&len) != EOF)
{
memset(res,-1,sizeof res);
for(int i = 0;i < len;i++)
scanf("%d",&array[i]);
res[0] = 1;
mark[0] = array[0];
printf("%d\n",func(len-1));
//for(int i = 0;i <= len-1;i++) cout<<mark[i]<<' ';cout<<endl;
//system("pause");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator