HDU 1715 大菲波数

9 篇文章 0 订阅
#include <iostream>
#include <string.h>
using namespace std;  
int s[1001][1001];
void fun(int s1[],int s2[],int s3[])
{
	int i;
	memset(s3,0,sizeof(int)*1000);
    for(i=0;i<=1000;i++)
	{
		s3[i]+=s1[i]+s2[i];
		s3[i+1]=s3[i]/10000000;
		s3[i]%=10000000;
	}
}
int main()  
{  
    int n,i,k;
	s[1][0]=s[2][0]=1;
    for(i=3;i<=1000;i++)
	{
		fun(s[i-2],s[i-1],s[i]);
	}
	while (cin>>n)
	{
		while(n-- && cin>> k)
		{
            i=1000;
        while(!s[k][i])  i--;
		cout<<s[k][i--];
		for (;i>=0;i--)
		   printf("%07d",s[k][i]);
		cout<<endl;
		}
	}
    return 0;  
}
</pre><pre code_snippet_id="625045" snippet_file_name="blog_20150322_5_3539545" name="code" class="cpp">
</pre><pre code_snippet_id="625045" snippet_file_name="blog_20150322_5_3539545" name="code" class="cpp">


2015 11 30
#include <iostream>
#include <algorithm>
using namespace std;


int num[1001][500];




void main()
{
    int i,j,k;
    int m,t;
<span style="white-space:pre">	</span>int n,v,w;
<span style="white-space:pre">	</span>int cnt ;


<span style="white-space:pre">	</span>num[1][0]=num[2][0]=1;
<span style="white-space:pre">	</span>for(i=3;i<=1000;i++)
<span style="white-space:pre">		</span>for(j=0;j<500;j++)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>num[i][j] += num[i-1][j] + num[i-2][j];
<span style="white-space:pre">			</span>num[i][j+1] = num[i][j]/10000000;
<span style="white-space:pre">			</span>num[i][j] %= 10000000;
            
<span style="white-space:pre">		</span>}




<span style="white-space:pre">	</span>cin>>t;
<span style="white-space:pre">	</span>while (t--)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>scanf("%d",&n);
<span style="white-space:pre">		</span>j=499;
<span style="white-space:pre">		</span>while(!num[n][j])
<span style="white-space:pre">			</span>j--;
<span style="white-space:pre">		</span>printf("%d",num[n][j]);
<span style="white-space:pre">		</span>for(i=j-1;i>=0;i--)
<span style="white-space:pre">			</span>printf("%07d",num[n][i]);
<span style="white-space:pre">		</span>cout<<endl;
<span style="white-space:pre">	</span>}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值