1136. Parliament

http://acm.timus.ru/problem.aspx?space=1&num=1136

水题

代码:

#include<iostream>

#include<cstdio>

#include<cstring>

#include<string>

#include<vector>

#include<queue>

#include<map>

#include<stack>

#include<algorithm>

#include<cmath>



using namespace std;

//#pragma comment(linker,"/STACK:1000000000,1000000000")



#define LL long long



const int INF=0x3f3f3f3f;

const int N=3005;

int a[N];

void dfs(int l,int r)

{

    if(l>r)

    return ;

    int i;

    for(i=l;i<r;i++)

    if(a[i]>a[r])

    break;

    dfs(i,r-1);

    dfs(l,i-1);

    cout<<a[r]<<" ";

}

int main()

{

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

    int n;

    while(cin>>n)

    {

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

        scanf("%d",&a[i]);

        dfs(0,n-1);

    }

    return 0;

}

 

你可能感兴趣的:(li)