hiho week 220 register

Ended

Participants:659

Verdict:Accepted
Score:100 / 100
Submitted:2018-09-16 15:40:29

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
using namespace std;
int n;
void dfs(int st, string tmp, string ans, int last)
{
    if ( st == 0 && tmp.length() == 0 )
    {
        cout<<ans<<endl;
        return ;
    }
    for ( int i = 0 ; i < n ; i++ )
    {
        if ( st & (1<<i) )
        {
            if ( i > last )
                dfs(st^(1<<i), "", ans+char('1'+i) + ((st^(1<<i)) ? "-" : "" ), -1);
            if ( i > last )
                dfs(st^(1<<i), tmp+char('1'+i), ans+char('1'+i), i);
        }
    }
}
int main()
{
    cin>>n;
    dfs((1<<n)-1, "", "", -1);
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX