我们模拟赛的题面
我的代码
#include<bits/stdc++.h>
using namespace std;
int a[30],ans;
int main() {
freopen("xpy.in","r",stdin);
freopen("xpy.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,k;
cin>>n>>k;
int Pow=1;
for(int i=1; i<=n; i++) {
a[i]=n-i+1;
Pow*=i;
}
for(int i=1; i<=Pow; i++) {
bool o=1;
next_permutation(a+1,a+n+1);
for(int x=1; x<=n; x++)
if(x!=1&&abs(a[x]-a[x-1])==k){
o=0;
break;
}
if(o) ans++;
}
cout<<ans;
return 0;
}
就只是因为最内层循环if中的break赛时没有加,TLE了,就这么丢了10分,好可惜啊