IDA* 但是 TLE 80分 on 3 4

P2534 [AHOI2012] 铁盘整理

教教我如何同时做三道题把
by fjy666 @ 2022-07-09 17:28:25


@[fjy666](/user/366338) 把今天所有写挂的题全扔上来了
by 蒟酱 @ 2022-07-09 17:29:39


```cpp #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cassert> #include<bits/stdc++.h> #define siz(x) int((x).size()) #define cauto const auto #define all(x) (x).begin(),(x).end() using namespace std; using loli=long long; using venti=__int128_t; using pii=std::pair<int,int>; constexpr int kN=20; int n,a[kN],dep,b[kN]; bool dfs(int now,int h,int pre){ if(now==dep)return !h; for(int i=2;i<=n;i++){ if(i==pre||abs(a[i+1]-a[i])==1)continue; std::reverse(a+1,a+1+i); int nh=h-(abs(a[i+1]-a[i])==1); if(now+nh<=dep&&dfs(now+1,nh,i))return true; std::reverse(a+1,a+1+i); } return 0; } signed main(){ // freopen(".in","r",stdin); // freopen(".out","w",stdout); std::ios::sync_with_stdio(false);cin.tie(nullptr); cin>>n;a[n+1]=n+1; for(int i=1;i<=n;i++)cin>>a[i],b[i]=a[i]; a[n+1]=n+1; sort(b+1,b+n+1); for(int i=1;i<=n;i++)a[i]=lower_bound(b+1,b+n+1,a[i])-b; for(dep=0;;dep++)if(dfs(0,[]{ int h=0;for(int i=1;i<=n;i++)h+=(abs(a[i]-a[i+1])!=1);return h; }(),0))return cout<<dep,0; } ```
by Awlgot @ 2022-07-09 23:11:37


问题是数组开小了
by 蒟酱 @ 2022-07-09 23:20:29


|