CodeForces 598E Chocolate Bar
2016-05-07 20:47
344 查看
区间DP预处理。
dp[i][j][k]表示大小为i*j的巧克力块,切出k块的最小代价。
dp[i][j][k]表示大小为i*j的巧克力块,切出k块的最小代价。
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const long long INF=9999999999999999; const int maxn=60; long long dp[maxn][maxn][maxn]; int n,m,k; void f() { for(int i=1;i<=30;i++) { for(int j=1;j<=30;j++) { for(int k=1;k<=50;k++) { dp[i][j][k]=INF; if(k>i*j) continue; if(k==0) { dp[i][j][k]=0; continue; } if(k==i*j) { dp[i][j][k]=0; continue; } //行割 for(int s=1;s<=i-1;s++) { for(int h=0;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=1;s<=j-1;s++) { for(int h=0;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 [m][k]); } return 0; }
相关文章推荐
- 玩转Android之加速度传感器的使用,模仿微信摇一摇
- 玩转Android之加速度传感器的使用,模仿微信摇一摇
- 玩转Android之加速度传感器的使用,模仿微信摇一摇
- Zimbre RROR: Installation can not proceeed. Please fix your /etc/hosts file 报错解决方法
- zoj-3785-What day is that day?
- jQuery操作DOM节点的相关方法
- ffmpeg音频编码
- 玩转Android之加速度传感器的使用,模仿微信摇一摇
- CodeForces 598D Igor In the Museum
- 二进制与十六进制
- 手机分辨率
- 一个帖子学会Android开发四大组件
- c/c++中与时间相关的问题
- LeetCode Swap Nodes in Pairs
- Eclipse Che开发Spring Web应用(入门) (二)
- [LeetCode61]Rotate List
- hdu 2588 gcd 欧拉函数
- secure crt 基本设置
- CodeForces 598C Nearest vectors
- powerpc eldk:Invalid configuration ppc_6xx :machine ppc_6xx not recognized