【COCI2015】【BZOJ3810】Stanovi

Description
这里写图片描述

Input

输入一行,三个整数,n, m, k
Output

输出一个数,表示最小不满意度。
Sample Input

3 3 2
Sample Output

1

【Hint】

见描述中的左图的分割方案,最小不满意度为4 * (2 - 2) ^ 2 + (1 - 2) ^ 2 = 1。

【数据范围】

n, m <= 300

k <= 10000

HINT

Source

鸣谢 Dzy

直接记忆化搜索.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long
#define GET (ch>='0'&&ch<='9')
using namespace std;
const LL MAXLL=1ll<<62;
template<class classname>
inline void in(classname &x)
{
    char ch=getchar();x=0;
    while (!GET)    ch=getchar();
    while (GET) x=x*10+ch-'0',ch=getchar();
}
int n,m,k;
LL f[310][310][2][2][2][2];
LL dfs(int x,int y,int a,int b,int c,int d)
{
    LL ret=1ll*(x*y-k)*(x*y-k);int na,nb,nc,nd;
    if (x>y) swap(x,y),na=a,nb=b,nc=c,nd=d,a=nb,b=nc,c=nd,d=na;
    if (a>c) swap(a,c);
    if (b>d) swap(b,d);
    if (f[x][y][a][b][c][d]!=-1)    return f[x][y][a][b][c][d];
    if (!a&&!b&&!c&&!d) return f[x][y][a][b][c][d]=MAXLL;
    if (a+b+c>0&&a+d+c>0) for (int i=1;i<x;i++)    ret=min(ret,dfs(i,y,a,b,c,0)+dfs(x-i,y,a,0,c,d));
    if (a+b+d>0&&b+c+d>0) for (int i=1;i<y;i++)    ret=min(ret,dfs(x,i,a,b,0,d)+dfs(x,y-i,0,b,c,d));
    return f[x][y][a][b][c][d]=ret;
}
int main()
{
    in(n);in(m);in(k);memset(f,-1,sizeof(f));
    cout<<dfs(n,m,1,1,1,1)<<endl;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值