心如止水
Je n'ai pas le temps
posts - 400,comments - 130,trackbacks - 0
仔细观察,很容易发现规律。
以下是我的代码:
#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 阅读(200) 评论(0)  编辑 收藏 引用 所属分类: 题目分类:递推/递归

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理