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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
#define mk make_pair
#define fi first
#define sz(x) x.size()
#define se second
#define pb push_back
#define VAR(v) #v << " " << v << " "
#define debug if(0)
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = (int)1e6 + 9;
const int INF = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
int n;
int dp[maxn];
int a[49];
ii ans[49];

int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    debug; else cin.tie(NULL), cout.tie(NULL);
    cin>>n;
    for(int i = 0; i < n; i++)
        cin>>a[i];

    for(int mask = 1; mask < (1<<n); mask++)
    {
        int right = 0;
        for(int i = 0; i < n; i++)
            if((1<<i) & mask)
                right = i;
        int cnt = 0;
        for(int i = 0; i < n; i++)
            if(((1<<i) & mask) && a[i] > a[right])
                cnt++;
        dp[mask] = dp[mask^(1<<right)] + cnt;
    }
    for(int i = 1; i <= n; i++)
        ans[i] = {INF, 0};
    for(int mask = 1; mask < (1<<n); mask++)
    {
        int k = 0;
        for(int i = 0; i < n; i++)
            if((1<<i) & mask) k++;
        if(ans[k].fi == dp[mask])
            ans[k].se++;
        else if(dp[mask] < ans[k].fi)
            ans[k] = {dp[mask], 1};
    }
    for(int i = 1; i <= n; i++)
        cout<<ans[i].fi<<" "<<ans[i].se<<"\n";
    return 0;
}