比赛 |
SBOI2022暑假快乐赛① |
评测结果 |
AEEEEEEEE |
题目名称 |
送礼物 |
最终得分 |
11 |
用户昵称 |
ZRQ |
运行时间 |
1.604 s |
代码语言 |
C++ |
内存使用 |
5.10 MiB |
提交时间 |
2022-06-25 11:10:21 |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<vector>
#include<algorithm>
using namespace std;
const int N=50;
int w,n,g[N],ans;
vector<int> b;
char ch;
void read(int &x){x=0;ch=getchar();while(ch<47||ch>58)ch=getchar();while(ch>47&&ch<58)x=(x<<3)+(x<<1)+(ch^48),ch=getchar();}
void SA()
{
random_shuffle(g+1,g+1+n);
int tot=0,k=1;
for(int i=1;i<=n;++i)
if(tot+g[i]<=w) b.push_back(g[i]),tot+=g[i],k=i+1;
sort(b.begin(),b.end());
for(double t=1e2;t>=1e-2;t*=0.99)
{
int x=tot;
int n1=k+rand()%(n-k+1);
int pos=rand()%(k-1);
if(!pos) ++pos;
int y=tot+g[n1]-b[pos],tmp;
if(y<=w&&exp(-(y-x)/t)>(double)rand()/RAND_MAX) tot=y,tmp=g[n1],g[n1]=b[pos],b[pos]=tmp;
}
ans=max(ans,tot);
return ;
}
int main()
{
freopen("giftgiving.in","r",stdin);
freopen("giftgiving.out","w",stdout);
srand(19260817);
read(w),read(n);
for(int i=1;i<=n;++i) read(g[i]);
for(int i=1;i<=5;++i) SA();
printf("%d\n",ans);
return 0;
}