• 递增序列(迭代加深)


    描述
    依次给你一个递增的数列,第一次给你1,第二次开始,每次给的数字是之前某两次和。告诉你一个数字M,表示第n次给你的数字,求最小的n,同时打印出这n个数的数列,有多组解输出任意
    输入
    一行,只有一个整数m
    输出
    第一行输出n。第二行输出数列,每两个数之间有且仅有一个空格。
    样例输入
    4
    样例输出
    3
    1 2 4
    提示
    本次是数字4。第一次1,第二次2,第三次(当前)4 。
    测试点编号 M 测试点编号 M
    1 <=20 ;6 <=1000
    2 <=30;7 <=2500
    3 <=40 ;8 <=3000
    4 <=50 ;9 <=4000
    5 <=60 ;10 <=5000

    只会打表啊

    要迭代加深

    不断增加层数

    看是否能搜索到

    不能贪心一直往后跑

    #include<bits/stdc++.h>
    using namespace std;
    inline int read(){
    	char ch=getchar();
    	int res=0;
    	while(!isdigit(ch)) ch=getchar();
    	while(isdigit(ch)) res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
    	return res;
    }
    int n,stk[5005],m,top=1;
    inline void write(){
    	cout<<top<<'
    ';
    	for(int i=1;i<=top;++i)cout<<stk[i]<<" ";
    	exit(0);
    }
    bool dfs(int pos){
    	if(stk[pos-1]==n)write();
    	if(pos>top)return false;	
    	for(int i=pos-1;i>=1;--i){
    		for(int j=pos-1;j>=i;--j){
    			stk[pos]=stk[i]+stk[j];
    			if((stk[pos]<<(top-pos))<n)break;
    			if((stk[pos]+(top-pos))>n)break;
    			if(stk[pos]<=stk[pos-1])break;
    			dfs(pos+1);
    		}
    	}
    	return false;
    }
    int main(){
    //	freopen("sequence.in","r",stdin);
    //	freopen("sequence.out","w",stdout);
    	n=read();
    	stk[1]=1;
    	while(!dfs(2))++top;
    }
    
  • 相关阅读:
    HGOI 20200724
    HGOI 20200722
    [USACO Open08]牛的邻居Cow Neighborhoods解题报告
    [USACO Jan07]考试Schul解题报告
    [CF 249D]Donkey and Start解题报告
    [CF 321D]Ciel and Flipboard解题报告
    [CF 294D]Shaass and Painter Robot解题报告
    [CF 297E]Mystic Carvings解题报告
    [CF 306E]Levko and Game题解翻译
    [CF 316F3]Suns and Rays解题报告
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/10366426.html
Copyright © 2020-2023  润新知