刚刚随机跳到了 P3052,看着数据范围想着能不能乱搞一下,于是每次把序列 shuffle 然后 O(n) 求解只能相邻的分为一组的情况,重复了 2e6 次再加上小幅度扩大每组重量上限,就这么水过去了。
如果我是出题人,出了一道类似这样的题,有没有什么好方法卡掉这种纯乱搞。
代码大概长成这样:
#include<bits/stdc++.h>
using namespace std;
int n,w,a[20],ans=1e9,now,tot;
int main(){
srand(time(0));
cin>>n>>w; w*=1.05;
for(int i=1;i<=n;++i) cin>>a[i];
for(int i=1;i<=2000000;++i){
random_shuffle(a+1,a+n+1);
tot=1; now=0;
for(int j=1;j<=n;++j) {
if(now+a[j]>w) now=a[j],tot++;
else now+=a[j];
}
ans=min(ans,tot);
}
cout<<ans;
return 0;
}
我不知道这算不算tlqtj,如果算我会马上删掉。