BZOJ 3810: [Coci2015]Stanovi

4 篇文章 0 订阅

搜索+优化….
貌似没什么好说的(逃

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=302; const LL inf=1ll<<60;
inline int read(){
    char ch=getchar(); int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0'; ch=getchar();}
    return x*f;
}
int n,m,k; LL f[N][N][2][2][2][2];
LL dfs(int x,int y,int a,int b,int c,int d){
    if(x>y) x^=y^=x^=y,a^=c^=a^=c,b^=d^=b^=d;
    if(a>b) a^=b^=a^=b;
    if(c>d) c^=d^=c^=d;
    if(f[x][y][a][b][c][d]<inf)return f[x][y][a][b][c][d];
    LL u=(LL)(x*y-k)*(LL)(x*y-k); int i;
    if(a || b || (c&&d))
        for(i=1;i<x;++i) u=min(u,dfs(i,y,a,b,0,d)+dfs(x-i,y,a,b,c,0));
    if(c || d || (a&&b))
        for(i=1;i<y;++i) u=min(u,dfs(x,i,a,0,c,d)+dfs(x,y-i,0,b,c,d));
    return f[x][y][a][b][c][d]=u;
}
int main()
{
    n=read(),m=read(),k=read();
    for(int i=1;i<N;++i)for(int j=1;j<N;++j)
        for(int a=0;a<2;++a)for(int b=0;b<2;++b)
            for(int c=0;c<2;++c)for(int d=0;d<2;++d)
                f[i][j][a][b][c][d]=inf;
    printf("%lld\n",dfs(n,m,1,1,1,1));
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值