比赛 |
noip |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
__围栏问题 |
最终得分 |
100 |
用户昵称 |
_Itachi |
运行时间 |
11.004 s |
代码语言 |
C++ |
内存使用 |
6.50 MiB |
提交时间 |
2016-11-04 19:07:22 |
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=17,INF=0x3f3f3f3f;
int n,m,K,N,x[maxn],y[maxn],g[1<<maxn],f[1<<maxn][maxn];
void Rabit_in(){
scanf("%d%d%d",&m,&K,&n);int i,v,l,r,s,t;
for(i=0;i<n;i++)scanf("%d%d",&x[i],&y[i]);
N=1<<n;
for(v=1;v<N;v++){
s=l=m,t=r=0;
for(i=0;i<n;i++)
if(v&(1<<i)){
if(s>x[i])s=x[i];
if(t<x[i])t=x[i];
if(l>y[i])l=y[i];
if(r<y[i])r=y[i];
}
g[v]=t-s+r-l+2;
}
}
void Rabit_min(int &x,int y){if(x>y)x=y;}
int Rabit_ans(){
memset(f,0x3f,sizeof(f));
f[0][0]=0;int v,i,j,ans=INF;
for(v=1;v<N;v++)
for(i=v;i;i=(i-1)&v)
for(j=1;j<=K;j++)
Rabit_min(f[v][j],f[v^i][j-1]+g[i]);
for(i=1;i<=K;i++)
Rabit_min(ans,f[N-1][i]);
return ans;
}
void Rabit_main(){
Rabit_in();
printf("%d\n",Rabit_ans()<<1);
}
int main(){
#define _Rabit _RABIT
#ifdef _Rabit
freopen("xfence.in","r",stdin);
freopen("xfence.out","w",stdout);
#endif
Rabit_main();
#ifndef _Rabit
getchar(),getchar();
#endif
fclose(stdin);fclose(stdout);
return 0;
}