#include#include#include#include#include#include#include#include#defineLLlonglongusingnamespacestd;constintN" />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

poj 1095 Trees Made to Order

系統(tǒng) 2166 0

http://poj.org/problem?id=1095

先打個表 然后dfs一下

      #include<iostream>

#include<cstdio>

#include<cstdlib>

#include<ctime>

#include<queue>

#include<cstring>

#include<set>

#include<cmath>

#include<algorithm>

#define LL long long



using namespace std;



const int N=25;

int a[N];

void begin()

{

    a[0]=1;

    a[1]=1;

    for(int i=2;i<N;++i)

    {

        a[i]=0;

        for(int l=0;l<i;++l)

        {

            a[i]+=(a[l]*a[i-l-1]);

        }

    }

}

int I;

void dfs(int k,int s)

{

    if(k==1)

    {

        printf("X");

        return ;

    }

    int l;

    int sum=0;

    for(l=0;l<k;++l)

    {

        sum+=a[l]*a[k-l-1];

        if(sum>=s)

        {

            sum-=a[l]*a[k-l-1];

            break;

        }

    }

    sum=s-sum;

    int w=sum/a[k-l-1];

    if(sum%a[k-l-1])

    ++w;

    if(l>0)

    {

        printf("(");

        dfs(l,w);

        printf(")");

    }

    printf("X");

    if(k-l-1>0)

    {

        printf("(");

        dfs(k-l-1,sum-(w-1)*a[k-l-1]);

        printf(")");

    }





}

int main()

{

    //freopen("data.txt","r",stdin);

    begin();

    int n;

    while(scanf("%d",&n)!=EOF)

    {

        if(n==0)

        break;

        int sum=0;I=0;

        for(int i=1;i<=N;++i)

        {

            sum+=a[i];

            if(sum>=n)

            {

                dfs(i,n-(sum-a[i]));

                break;

            }

        }

        printf("\n");

    }

    return 0;

}


    

poj 1095 Trees Made to Order


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 云梦县| 军事| 吉木萨尔县| 泽普县| 中卫市| 常熟市| 嘉定区| 元氏县| 延津县| 周至县| 邵阳县| 青海省| 沅江市| 读书| 崇礼县| 红桥区| 张家川| 阿克| 湘潭县| 内黄县| 桓台县| 乌兰浩特市| 鄂伦春自治旗| 饶平县| 宿迁市| 介休市| 平昌县| 柘城县| 通渭县| 远安县| 岐山县| 桂平市| 金阳县| 平潭县| 海丰县| 南宫市| 宝山区| 阿巴嘎旗| 永丰县| 灌阳县| 株洲市|