100的数据直接暴力就行,想多了。。。
ac的代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#define LL __int64
const int maxn = +;
using namespace std;
int a[maxn], sum; class SortishDiv2
{
public:
int ways(int sortedness, vector <int> seq)
{
int f[maxn], len, i, j, ans = ;
int cnt = , x[maxn];
len = seq.size();
memset(f, , sizeof(f));
for(i = ; i < len; i++)
f[seq[i]] = ;
for(i = ; i <= len; i++)
if(f[i]==)
x[cnt++] = i;
sort(x, x+cnt);
do
{
int y = ;
for(i = ; i < len; i++)
{
if(seq[i]==) a[i] = x[y++];
else a[i] = seq[i];
}
sum = ;
for(i = ; i < len; i++)
for(j = i+; j < len; j++)
if(a[j]>a[i])
sum ++;
if(sum == sortedness) ans ++;
}
while (next_permutation(x,x+cnt)); //数字的全排列 return ans;
}
}; /*int main()
{
SortishDiv2 s;
int i, j, n, y, tmp;
vector<int>v;
while(1)
{
v.clear();
cin>>n; cin>>y;
for(i = 0; i < y; i++)
{
cin>>tmp;
v.push_back(tmp);
}
cout<<s.ways(n, v)<<endl;
}
return 0;
}*/