CodeForces 598E Chocolate Bar
区间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的更多相关文章
- Codeforces Problem 598E - Chocolate Bar
Chocolate Bar 题意: 有一个n*m(1<= n,m<=30)的矩形巧克力,每次能横向或者是纵向切,且每次切的花费为所切边长的平方,问你最后得到k个单位巧克力( k <= ...
- codeforces 598E E. Chocolate Bar(区间dp)
题目链接: E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces 598E:Chocolate Bar
E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索
E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...
- 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 ...
- Chocolate Bar(暴力)
Chocolate Bar Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement There is ...
- Codeforces 490D Chocolate
D. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- codeforces 617B Chocolate
题意: 在给定01串中,问能分割成多少个子串?每个子串只有一个1. dp #include<iostream> #include<string> #include<alg ...
- 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 ...
随机推荐
- think in uml 1
对象,在过程的基础上,是一个抽象级别的提升,可以构建更大更复杂的系统 数据流图(Data Flow Diagram):简称DFD,它从数据传递和加工角度,以图形方式来表达系统的逻辑功能.数据在系统内部 ...
- swfupload在chrome中点击上传图片按钮无反应的解决办法
chrome 22.0.XXXXX dev版上传图片按钮点击无反应原因:是GOOGLE的内建Flash PPAPI外挂所导致的. 问题原因: 由于Google浏览器(Chrome),在最新测试版22. ...
- OpenGL红宝书例子2.2 uniform变量的使用
1. 简单介绍一下OpenGL可编程渲染管线的流程 顶点着色 --> 细分着色 --> 几何着色 --> 片元着色 --> 计算着色 一般我们主要参与的阶段是顶点着色和片元着色 ...
- linux的学习系列 2--文件系统
Linux中的所有数据都被保存在文件中,所有的文件被分配到不同的目录.目录是一种类似于树的结构,称为文件系统. 当你使用Linux时,大部分时间都会和文件打交道,通过本节可以了解基本的文件操作,如创建 ...
- Moya 浅析
Moya是一个高度抽象的网络库,他的理念是让你不用关心网络请求的底层的实现细节,只用定义你关心的业务.且Moya采用桥接和组合来进行封装(默认桥接了Alamofire),使得Moya非常好扩展,让你不 ...
- python 对比图片相似度
最近appium的使用越来越广泛了,对于测试本身而言,断言同样是很重要的,没有准确的断言那么就根本就不能称之为完整的测试了.那么目前先从最简单的截图对比来看.我这里分享下python的图片相似度的代码 ...
- lucene3.6.1 经典案例 入门教程 (包含从文件中读取content)
转载http://liqita.iteye.com/blog/1676664 第一步:下载lucene的核心包 lucene-core-3.6.1-javadoc.jar (3.5 MB) lucen ...
- PAT (Advanced Level) 1104. Sum of Number Segments (20)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- C# 初步学习
这学期有了C#开发这门课....先做了计算器,还有进制转换,别人看来似乎很强,其实在ACM中算是两个简单的水题了.....参加竞赛一年下来,发现学到的算法和数据结构都是十分有用的东西. 计算器最核心的 ...
- linux自动化构建工具-scons指南
1.scons是linux下的自动构建工具 scons是用Python编写的,使用scons之前需确认是否已经安装了Python.(在系统的命令行中运行python -V或python --versi ...