比赛 |
noip |
评测结果 |
RRRRRRRRRRRRRRRRRRRR |
题目名称 |
__完全平方数 |
最终得分 |
0 |
用户昵称 |
jiazihankk |
运行时间 |
0.084 s |
代码语言 |
C++ |
内存使用 |
3.14 MiB |
提交时间 |
2016-11-04 21:56:12 |
显示代码纯文本
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i,k,n) for(int i=k;i<=n;i++)
using namespace std;
const int inf=0x3f3f3f3f;
const int M=67777;
const int N=16;
int f[10][M],x[N],y[N],K,n,m,S,val[M],ans;
void init(int s){
int mi_x,mx_x,mi_y,mx_y;
mi_x=mi_y=M;
mx_x=mx_y=-1;
rep(i,0,n-1)if((s>>i)&1){
mi_x=min(mi_x,x[i]);
mi_y=min(mi_y,y[i]);
mx_x=max(mx_x,x[i]);
mx_y=max(mx_y,y[i]);
}mi_x--,mi_y--;
val[s]=2*(mx_x-mi_x + mx_y-mi_y);
}
int main(){
freopen("xfence.in","r",stdin);
freopen("xfence.out","w",stdout);
scanf("%d%d%d",&m,&K,&n);
memset(f,0x3f,sizeof(f));
rep(i,0,n-1)scanf("%d%d",&x[i],&y[i]);
S=(1<<n)-1;
rep(i,1,S)init(i),f[1][i]=val[i];
ans=val[S];
rep(k,1,(K+1)/2-1){memcpy(f[k+1],f[k],sizeof(f[k]));
rep(s,1,S){int res=f[k][s];
int u=S^s;
for(;u;u-=(u&-u))f[k+1][s^u]=min(f[k+1][s^u],res+val[u]);
}
}
rep(k,1,(K+1)/2){
rep(s,1,S)
ans=min(ans,f[k][s]+f[K-k][S^s]);
}
printf("%d\n",ans);
}