• 【ybtoj】【递推】平铺方案


    题意

    image

    题解

    非常水的小递推,转移十分显然。
    唯一特殊的就是要用高精,很久没写了,贴个模板上来纪念一下。
    如果有时间再把压位高精补了。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    const int INF = 0x3f3f3f3f;
    inline ll read()
    {
    	ll ret=0;char ch=' ',c=getchar();
    	while(!(c>='0'&&c<='9')) ch=c,c=getchar();
    	while(c>='0'&&c<='9') ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
    	return ch=='-'?-ret:ret;
    }
    int n;
    struct haa
    {
    	int a[1005],len=1;
    	haa(){}
    	haa(int x)
    	{
    		memset(a,0,sizeof(a));len=1;
    		while(x){a[len++]=x%10;x/=10;} len--;
    	}
    }f[255];
    haa operator + (const haa &a,const haa &b)//高精加高精 
    {
    	haa ret=0;ret.len=max(a.len,b.len)+1;
    	int up=0;
    	for(int i=1;i<=ret.len;i++)
    	{
    		ret.a[i]+=a.a[i]+b.a[i]+up;
    		up=ret.a[i]/10;
    		ret.a[i]%=10;
    	}
    	while(ret.len>1&&!ret.a[ret.len]) ret.len--;
    	return ret;
    }
    haa operator * (const haa &a,const int b)//高精乘低精 
    {
    	haa ret=0;ret.len=a.len+1;
    	int up=0;
    	for(int i=1;i<=ret.len;i++)
    	{
    		ret.a[i]=a.a[i]*b+up;
    		up=ret.a[i]/10;
    		ret.a[i]%=10;
    	}
    	while(ret.len>1&&!ret.a[ret.len]) ret.len--;
    	return ret;
    }
    int main()
    {
    	f[1]=1,f[2]=3;
    	n=250;
    	for(int i=3;i<=n;i++) f[i]=f[i-2]*2+f[i-1];
    	int k;
    	while(scanf("%d",&k)!=EOF)
    	{
    		for(int i=f[k].len;i>=1;i--)
    			printf("%d",f[k].a[i]);
    		printf("
    ");
    	}
    	return 0;
    }
    
  • 相关阅读:
    https://blog.csdn.net/nameofcsdn/article/details/53164652
    洛谷
    模板
    模板
    Gym 101911E "Painting the Fence"(线段树区间更新+双端队列)
    Gym 101911F “Tickets”
    图论:最小瓶颈生成树
    图论:次小生成树
    图论:费用流-SPFA+EK
    图论:Dinic算法
  • 原文地址:https://www.cnblogs.com/conprour/p/15315602.html
Copyright © 2020-2023  润新知