仔细观察,很容易发现规律。
以下是我的代码:
#include<stdio.h>
#define MAXN 1010
typedef unsigned long Long;
Long f(Long x,Long a)


{
Long i,re=1;
for(i=1;i<=a;i++)
re*=x;
return re;
}
int main()


{

Long k,n,i,count,tot,tmp,a[MAXN]=
{0};
scanf("%lu%lu",&k,&n);
tot=0;
count=0;
while(tot<n)

{
tot++;
tmp=tot;
a[tot]=f(k,count);
count++;
for(i=1;i<tmp;i++)

{
tot++;
a[tot]=a[i]+a[tmp];
if(tot>=n) break;
}
}
printf("%lu\n",a[n]);
// getchar();getchar();
return 0;
}

posted on 2010-01-06 20:33
lee1r 阅读(228)
评论(0) 编辑 收藏 引用 所属分类:
题目分类:递推/递归