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 ...
随机推荐
- Hibernate 系列教程7-双向一对一
双向一对一 一对一主要用在 一个一方需要的信息比较少,比如注册的登录信息 另一个一方存储的信息比较多,比如注册之后用户填写的详细信息 实现方式常用的主要有2种: java模型都是一样,其中一个映射文件 ...
- Swift -> Let & Var 背后编程模式 探讨
简介 Swift中有两种声明“变量”的方式,这两种方式分别使用let和var这两个关键字.这应该是借鉴了Scala,因为它们和Scala的val和var有相同的作用.let被用于声明不变量,var被用 ...
- Android ViewDragHelper完全解析 自定义ViewGroup神器
Android ViewDragHelper完全解析 自定义ViewGroup神器 转载请标明出处: http://blog.csdn.net/lmj623565791/article/detai ...
- GameUnity 2.0 文档(三) 纸片人八方向
DirectSprite类 有别于 上篇文档出现的 AnimationSprite类 (从头播放到尾) 这个类根据 path的图,如果是 8*8 64个图 八方向,可以设置长宽和 角度 角度 代表 8 ...
- 新手引导-ugui
http://www.unitymanual.com/thread-38287-1-1.html 我已经在 干货区发布了,所以 这里就记录一下地址,懒得再贴了 新年第一贴,大家 看完代码 ,是不是发现 ...
- java 多线程机制
Example12_1.java public class Example12_1 { public static void main(String args[]) { //主线程 SpeakElep ...
- Landsat TM DN值转为表观反射率
日地距离计算参见<中华人民共和国气象行业标准太阳能资源评估方法>
- CodeForces 678C Joty and Chocolate
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- 优化之sitemap+RSS
RSS也叫聚合, RSS是在线共享内容的一种简易方式,也叫聚合内容,Really Simple Syndication. 通常在时效性比较强的网站或网络平台上应用RSS订阅功能可以更快速获取信息,网站 ...
- Viewpager以及ViewPagerIndicator的相关使用
ViewPagerIndicator开源框架可以用来在ViewPager上方做标题,可以在ViewPager下方做跟随移动的小圆点,这个类库必须和自己的项目在电脑的同一磁盘盘符下,比如都在D盘或者E盘 ...