简单到极致的打表题解

· · 个人记录

这题……可以直接暴力打表

肥肠的香哦

题目说过,数据只有2*10^4 ,也就是20000,甚至于它只需要打表到2^14次方而已!

仔细看看就可以把2(0)~2(14)达标出来

只要能够突破逻辑思维,这题直接就Game Over了!

#include<iostream>
using namespace std;
int db[]={0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384};
string dba[]={"",
    "2(0)",
    "2",
    "2(2)",
    "2(2+2(0))",
    "2(2(2))",
    "2(2(2)+2(0))",
    "2(2(2)+2)",
    "2(2(2)+2+2(0))",
    "2(2(2+2(0)))",
    "2(2(2+2(0))+2(0))",
    "2(2(2+2(0))+2)",
    "2(2(2+2(0))+2+2(0))",
    "2(2(2+2(0))+2(2))",
    "2(2(2+2(0))+2(2)+2(0))",
    "2(2(2+2(0))+2(2)+2)",
};//整个程序的精华,我也就研究了5分钟左右
void B(int x)
{
    int step=1,i=14;
    while(i>0&&x>0)
    {
        if(x-db[i]>=0)
        {
            if(step!=1)
                cout<<'+';//一定要记得第一次的不加+
            cout<<dba[i];
            step++;
            x-=db[i];//记得减掉!不然它会把上面的String全输出
        }
        i--;//从大到小输出
    }
}
int main()
{
    int n;
    cin>>n;
    B(n);
    return 0;//打表结束,快乐哦
}

然后这个程序5个点AC,非常简单