Educational Codeforces Round 1 E. Chocolate Bar(记忆化搜索)
来源:互联网 发布:2016淘宝客赚不赚钱 编辑:程序博客网 时间:2024/05/23 14:34
题目链接
题意:在n*m的矩形切出面积是k
解法:记忆化搜索
#include<bits/stdc++.h>using namespace std;#define LL long long#define pb push_back#define X first#define Y second#define cl(a,b) memset(a,b,sizeof(a))typedef pair<int,int> P;const int maxn=100005;const LL inf=1<<27;const LL mod=1e9+7;LL dp[35][35][55];LL dfs(int n,int m,int k){ //printf("n = %d, m = %d, k = %d\n",n,m,k); if(k==0||m*n==k)return 0; if(dp[n][m][k]!=-1)return dp[n][m][k]; LL ans=inf; for(int i=1;i<n;i++){ for(int j=0;j<=k;j++){ ans=min(ans,dfs(i,m,j)+dfs(n-i,m,k-j)+(LL)m*m); } } for(int i=1;i<m;i++){ for(int j=0;j<=k;j++){ ans=min(ans,dfs(n,i,j)+dfs(n,m-i,k-j)+(LL)n*n); } } return dp[n][m][k]=ans;}int main(){ int T;scanf("%d",&T);cl(dp,-1); while(T--){ int n,m,k; scanf("%d%d%d",&n,&m,&k); printf("%lld\n",dfs(n,m,k)); } return 0;}
0 0
- Educational Codeforces Round 1 E. Chocolate Bar(记忆化搜索)
- Educational Codeforces Round 1 E Chocolate Bar(dp)
- CodeForces 598E Chocolate Bar(DP|记忆化搜索)
- Educational Codeforces Round 1 E.Chocolate Bar(DP)
- Coderforce 598 E. Chocolate Bar(DP,记忆化搜索)
- 【Educational Codeforces Round 1E】【动态规划-多维DP】Chocolate Bar 矩形巧克力掰开吃的最小成本
- Codeforces 598E:Chocolate Bar(DP)
- Codeforces 598E Chocolate Bar
- Codeforces 598E:Chocolate Bar
- Codeforces 598E Chocolate Bar
- Educational Codeforces Round 13 C Joty and Chocolate(数学)
- Educational Codeforces Round 16 (A-E)
- Codeforces Round #313 (Div. 1) E. Gerald and Path dp 记忆化搜索 stl应用
- Codeforces 598E Chocolate Bar (dp)
- Codeforces Problem 598E - Chocolate Bar
- Educational Codeforces Round 1 (D) 搜索(优化剪枝)
- Educational Codeforces Round 21E
- Educational Codeforces Round 26 E
- 学习spring汇总
- Android中使用log4j、android-logging-log4j-1.0
- OC简易通讯录
- KING_C#学习之各种基本数据类型的最大值最小值
- 继承组合优缺点
- Educational Codeforces Round 1 E. Chocolate Bar(记忆化搜索)
- hibernate中session接口方法总结
- Analyzing 1.1 Billion NYC Taxi and Uber Trips, with a Vengeance
- 数字转中文写法函数
- 备忘
- KVM在线迁移(动态迁移)—图形界面
- 修改时区名字
- State List
- 霍夫曼编码