Codeforces 598E Chocolate Bar
来源:互联网 发布:网络娱乐节目片头音乐 编辑:程序博客网 时间:2024/06/07 15:18
思路:
1. 首先注意到数据组数为1e4,每次算出的结果保留,待下次查询。
2. 定义状态dp[i][j][k]为边长i,j的矩形要得到k块所需的最小花费。
3. 注意状态转移,每次行列切割后,不是直接转移的到dp[i][j - a][k - a*i]之类。应当进行枚举,把目标k分散至分割后的部分。
1. 首先注意到数据组数为1e4,每次算出的结果保留,待下次查询。
2. 定义状态dp[i][j][k]为边长i,j的矩形要得到k块所需的最小花费。
3. 注意状态转移,每次行列切割后,不是直接转移的到dp[i][j - a][k - a*i]之类。应当进行枚举,把目标k分散至分割后的部分。
#include <set>#include <map>#include <ctime>#include <cmath>#include <stack>#include <queue>#include <deque>#include <cstdio>#include <string>#include <vector>#include <cctype>#include <sstream>#include <utility>#include <cstring>#include <cstdlib>#include <functional>#include <iostream>#include <algorithm>#define SF(a) scanf("%d", &a)#define PF(a) printf("%d\n", a) #define SFF(a, b) scanf("%d%d", &a, &b) #define SFFF(a, b, c) scanf("%d%d%d", &a, &b, &c)#define SFFFF(a, b, c, d) scanf("%d%d%d%d", &a, &b, &c, &d)#define CLEAR(a, b) memset(a, b, sizeof(a))#define IN() freopen("in.txt", "r", stdin)#define OUT() freopen("out.txt", "w", stdout)#define FOR(i, a, b) for(int i = a; i < b; ++i)#define LL long long#define mod 10007#define inf 100000007#define eps 1e-12using namespace std;int buf[20];int read() {int x = 0; char ch = getchar(); bool f = 0;while (ch < '0' || ch > '9') { if (ch == '-') f = 1; ch = getchar(); }while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();return f ? -x : x;}void write(int x) {if (!x) { putchar(48); return; }int l = 0; if (x < 0) putchar('-'), x = -x;while (x) buf[++l] = x % 10, x = x / 10;while (l) putchar(buf[l--] + 48);}//-------------------------chc------------------------------//const int maxn = 35;int squa[maxn], dp[maxn][maxn][55];bool vis[maxn][maxn][55];void pre() { FOR(i, 1, 31) squa[i] = i*i; }int solve(int r, int c, int k) {if (vis[r][c][k]) return dp[r][c][k];vis[r][c][k] = true;int &ret = dp[r][c][k];if (k == r * c || k == 0) return ret = 0;ret = inf;FOR(i, 1, r / 2 + 1) FOR(j, 0, k + 1)ret = min(ret, squa[c] + solve(i, c, j) + solve(r - i, c, k - j));FOR(i, 1, c / 2 + 1) FOR(j, 0, k + 1)ret = min(ret, squa[r] + solve(r, i, j) + solve(r, c - i, k - j));return ret;}int main() {int t = read();pre();while (t--) {int n, m, k;SFFF(n, m, k);PF(solve(n, m, k));}return 0;}
阅读全文
0 0
- Codeforces 598E Chocolate Bar
- Codeforces 598E:Chocolate Bar
- Codeforces 598E Chocolate Bar
- Codeforces 598E Chocolate Bar (dp)
- Codeforces Problem 598E - Chocolate Bar
- Codeforces 598E:Chocolate Bar(DP)
- Codeforces 598E Chocolate Bar 【区间dp + 打表】
- CodeForces 598E Chocolate Bar(DP|记忆化搜索)
- Educational Codeforces Round 1 E.Chocolate Bar(DP)
- Educational Codeforces Round 1 E Chocolate Bar(dp)
- Coderforce 598 E. Chocolate Bar(DP,记忆化搜索)
- Educational Codeforces Round 1 E. Chocolate Bar(记忆化搜索)
- 【Educational Codeforces Round 1E】【动态规划-多维DP】Chocolate Bar 矩形巧克力掰开吃的最小成本
- CF 598 E. Chocolate Bar dp题的要害是什么呢?
- AtCoder:Chocolate Bar(数学)
- Codeforces Jzzhu and Chocolate
- CodeForces 490D Chocolate
- codeforces 490 D Chocolate
- windows下如何创建.xxx文件夹
- 利用Visual Studio Natvis 框架简化C++的变量调试工作
- String,StringBuffer,StringBuilder的区别
- Spring-cloud-config用svn做配置中心
- (绝对干货!)安卓Context到底是什么?带你深度解析
- Codeforces 598E Chocolate Bar
- WebView的使用
- json数据格式的强大之处
- python3.6安装mayavi4.5
- SpringCloud传文件
- 使用jsonp解决ajax请求json跨域问题
- eclipse创建maven_maven插件配置
- Yarn_资源调度器
- 12-14笔记