区间DP预处理。

dp[i][j][k]表示大小为i*j的巧克力块,切出k块的最小代价。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const long long INF=;
const int maxn=;
long long dp[maxn][maxn][maxn];
int n,m,k; void f()
{
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
for(int k=;k<=;k++)
{
dp[i][j][k]=INF;
if(k>i*j) continue;
if(k==)
{
dp[i][j][k]=;
continue;
}
if(k==i*j)
{
dp[i][j][k]=;
continue;
}
//行割
for(int s=;s<=i-;s++)
{
for(int h=;h<=k;h++)
{
if(dp[s][j][h]==INF) continue;
if(dp[i-s][j][k-h]==INF) continue; dp[i][j][k]=min(
dp[i][j][k],
dp[s][j][h]+dp[i-s][j][k-h]+j*j
);
}
} //列割
for(int s=;s<=j-;s++)
{
for(int h=;h<=k;h++)
{
if(dp[i][s][h]==INF) continue;
if(dp[i][j-s][k-h]==INF) continue; dp[i][j][k]=min(
dp[i][j][k],
dp[i][s][h]+dp[i][j-s][k-h]+i*i
);
}
}
}
}
}
} int main()
{
f();
int T; scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
printf("%lld\n",dp[n][m][k]);
}
return ;
}

CodeForces 598E Chocolate Bar的更多相关文章

  1. Codeforces Problem 598E - Chocolate Bar

    Chocolate Bar 题意: 有一个n*m(1<= n,m<=30)的矩形巧克力,每次能横向或者是纵向切,且每次切的花费为所切边长的平方,问你最后得到k个单位巧克力( k <= ...

  2. codeforces 598E E. Chocolate Bar(区间dp)

    题目链接: E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  3. Codeforces 598E:Chocolate Bar

    E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  4. Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索

    E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...

  5. Educational Codeforces Round 1 E. Chocolate Bar dp

    题目链接:http://codeforces.com/contest/598/problem/E E. Chocolate Bar time limit per test 2 seconds memo ...

  6. Chocolate Bar(暴力)

    Chocolate Bar Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement There is ...

  7. Codeforces 490D Chocolate

    D. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  8. codeforces 617B Chocolate

    题意: 在给定01串中,问能分割成多少个子串?每个子串只有一个1. dp #include<iostream> #include<string> #include<alg ...

  9. Educational Codeforces Round 1

    598A - Tricky Sum    20171103$$ans=\frac{n(n+1)}{2} - 2\sum_{k=0}^{\left \lfloor \log_2 n \right \rf ...

随机推荐

  1. auto_ash

    #!/usr/bin/ksh ##############paramter######################startdate=$1' 00:00:01'enddate=$2' 23:59: ...

  2. 第四届河南省省赛 走迷宫 二分+DFS

    题目思路:使用二分查找路径中最大值和最小值之间的差值,从而确定出一组minn和maxn,对此组的minn和maxn经行DFS,如果可以找到一条路径,其中的最大值,最小值在minn~maxn的范围内,则 ...

  3. NBUT 1120 线段树

    input q n q行 F a b或者Q a b output face left face top face right 可以用map或者线段树做 //map #include<cstdio ...

  4. Swift 学习笔记(四)

    116.使用可选链式调用代替强制展开 通过在想调用的属性.方法.或下标的可选值(optional value)后面放一个问号(?),可以定义一个可选链.这一点很像在可选值后面放一个叹号(!)来强制展开 ...

  5. eclipse修改豆沙绿

    长时间的使用eclipse开发会很累吧  设置一个保护眼睛的豆沙绿色 不刺眼 是不是会更好一些呢 那么如何设置呢现在就教大家   工具/原料 eclipse jdk 方法/步骤 1 首先打开eclip ...

  6. gameUnity 网络游戏框架

    常常在想,有没有好的方式,让开发变得简单,让团队合作更加容易. 于是,某一天 动手写一个 架构, 目前版本 暂定 0.1 版本.(unity5.0.0f4 版本以上) 我打算 开源出来 0.1有什么功 ...

  7. FZU Problem 1895 整除45问题(整除问题+字符串维护+优化)

    这个题有点烧脑啊,但是只要想清楚被45整除的数,肯定能被5和9整除,能被9整除的数各位加起来肯定是9的倍数,能被5整除的末尾是0或5. 然后dfs的过程稍微不太好懂,还有几个优化必须要注意.dfs的过 ...

  8. String Stringbuilder Stringbuffer的区别

    String 字符串常量StringBuffer 字符串变量(线程安全)StringBuilder 字符串变量(非线程安全) 简要的说, String 类型和 StringBuffer 类型的主要性能 ...

  9. Python 安装matplotlib,six,dateutil,pyparsing 完整过程

    [摘要:正在做词频剖析的时间,须要用matlotlib 做图表,柱状图啥的,因而便最先了一个又一个的装置库的进程 由于matplotlib 须要依附很多其他科教盘算的第三圆库,须要一个一个的装置了.. ...

  10. select 通过表单提交获取select中的值

    <select class="txt" name="choice">       <option value="name" ...