标签:scanf name 树状数组 turn sum max += return bit
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100
int bit[MAX_N + 1], n;
long long f;
int a[MAX_N];
int sum(int i){
int s = 0;
while(i > 0){
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x){
while(i <= n){
bit[i] += x;
i += i & -i;
}
}
void solve()
{
long long ans = 0;
for(int j = 0; j < n; ++j){
ans += j - sum(a[j]);
add(a[j], 1);
}
f=f+ans;
}
int main()
{
while(~scanf("%d", &n))
{
f=0;
for(int i = 0; i < n; ++i){
scanf("%d", &a[i]);
}
//solve();
sort(a,a+n);
do{
memset(bit,0,sizeof(bit));
solve();
}while(next_permutation(a,a+n));
cout<<f<<endl;
}
return 0;
}
标签:scanf name 树状数组 turn sum max += return bit
原文地址:https://www.cnblogs.com/mch5201314/p/10716519.html