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 ...
随机推荐
- myeclipse 之 快捷键
简单记录一下,新装了个机器,win7系统,想设置一下自己习惯的快捷键 如:ctrl+alt+方向键,复制行,发现设置不上,原先的自带的也失效,设置一下ctrl+alt+其它键,ok可以使用,这说明某些 ...
- iptables基础知识
iptables防火墙可以用于创建过滤(filter)与NAT规则.所有Linux发行版都能使用iptables,因此理解如何配置 iptables将会帮助你更有效地管理Linux防火墙.如果你是第一 ...
- android--屏幕旋转方法总结
在介绍之前,我们需要先了解默认情况下android屏幕旋转的机制: 默认情况下,当用户手机的重力感应器打开后,旋转屏幕方向,会导致当前activity发生onDestroy-> onCreate ...
- LoadRunner 技巧之协议分析(五)
在做性能测试的时候,协议分析是困扰初学者的难题,选择错误的协议会导致Virtual User Generator 录制不到脚本:或录制的脚本不完整,有些应用可能需要选择多个协议才能完整的记录 客户端与 ...
- Theos tweak MSHookFunction
#import "substrate.h" static FILE * (*s_orig_fopen) ( const char * filename, const char * ...
- hdu 2612(Find a way)(简单广搜)
Find a way Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Su ...
- 7--OC中NSLog函数输出格式详解
OC中NSLog函数输出格式详解 • %@ 对象 • %d, %i 整数 • %u 无符整形 • %f 浮点/双字 • %x, %X 二进制整数 • %o 八进制整数 • %zu size_t • % ...
- Python文件打包成EXE文件
工具:pyinstaller 安装:pip install pyinstaller 使用: 1 将依赖文件集中到一个文件夹: pyinstaller -D -w xxx.py ...
- 转:设置Loadrunner负载机临时文件目录
最近在跑稳定性测试 3 X 24小时的时候,发现负载机产生的日志还运行记录等等竟然有100多G! C盘空间不足,但是D盘还有700多G空间呢,怎么让临时文件转移到D盘? 此处分两种情况: 一. 修改本 ...
- 浅谈:html5和html的区别
什么是html5呢? html5最先由WHATWG(Web 超文本应用技术工作组)命名的一种超文本标记语言,随后和W3C的xhtml2.0(标准)相结合,产生现在最新一代的超文本标记语言.可以简单点理 ...