您的位置:首页 > 产品设计 > UI/UE

【poj2081】Recaman's Sequence (动态规划DP)

2011-04-20 09:39 302 查看
#include<cstdio>
using namespace std;
bool isexist[3012505]={1};
int res[500005]={0};
int main()
{
int temp;
for (int m=1;m<=500000;m++)
{
temp=res[m-1]-m;
if((temp)>0 && !isexist[temp])
{
isexist[temp]=1;
res[m]=res[m-1]-m;
}
else
{
res[m]=res[m-1]+m;
if(!isexist[res[m]]) isexist[res[m]]=1;
}
}
while(scanf("%d",&temp)!=EOF && (temp!=-1))
printf("%d/n",res[temp]);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: